Files
orascheandClaude Fable 5 be519f9bc1 Context menu purge: drop .js from the callback module specifier
The backend context menu appends .js itself when importing the callback module; with the extension already in the attribute the browser requested ssr-context-menu.js.js and the click died silently. Confirmed working in the backend after the fix.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-11-09 21:14:50 +01:00

73 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Evomedien\Vitec\ContextMenu;
use TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Core\Environment;
/**
* Page tree context menu: "Purge from SSR cache" - evicts exactly this
* page from the SSR node's full-page cache, with toast feedback.
* Shown only for real pages and only while the purge endpoint is
* configured (var/vitec-ssr-purge.env).
*/
final class SsrPurgeItemProvider extends AbstractProvider
{
protected $itemsConfiguration = [
'ssrPurge' => [
'type' => 'item',
'label' => 'Purge from SSR cache',
'iconIdentifier' => 'actions-system-cache-clear-impact-medium',
'callbackAction' => 'ssrPurge',
],
];
public function canHandle(): bool
{
return $this->table === 'pages';
}
/**
* Below the core PageProvider (100): we run after it and splice our
* item into the finished menu, right behind "Clear cache".
*/
public function getPriority(): int
{
return 42;
}
public function addItems(array $items): array
{
if (!is_readable(Environment::getVarPath() . '/vitec-ssr-purge.env')) {
return $items;
}
$page = BackendUtility::getRecord('pages', (int)$this->identifier, 'uid,doktype');
if ($page === null || (int)$page['doktype'] >= 199) {
// Spacers, folders, recycler - nothing cached for those.
return $items;
}
$this->initDisabledItems();
$localItems = $this->prepareItems($this->itemsConfiguration);
if (isset($items['clearCache'])) {
$new = [];
foreach ($items as $key => $item) {
$new[$key] = $item;
if ($key === 'clearCache') {
$new = array_merge($new, $localItems);
}
}
return $new;
}
return array_merge($items, $localItems);
}
protected function getAdditionalAttributes(string $itemName): array
{
// No ".js" here: the context menu JS appends it when importing.
return ['data-callback-module' => '@evomedien/vitec/ssr-context-menu'];
}
}