Important: #94407 - Custom actions in the workspaces module
See forge#94407
Description
The record table of the workspaces backend module rendered a fixed set of action
buttons per record. Listeners of the PSR-14 event
\TYPO3\ could
neither add a button of their own nor hide or disable one of the buttons the
module renders itself, which left overriding the module's JavaScript as the only
option.
The buttons of a record are now described in an
actions
section, which a
listener can modify:
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Workspaces\Event\AfterDataGeneratedForWorkspaceEvent;
final class ModifyWorkspaceRecordActionsEventListener
{
#[AsEventListener('my-extension/modify-workspace-record-actions')]
public function __invoke(AfterDataGeneratedForWorkspaceEvent $event): void
{
$data = $event->getData();
$data['tt_content:42']['actions'] = [
// Render the publish button greyed out
'publish' => ['enabled' => false],
// Remove the discard button from the record
'remove' => ['visible' => false],
// Add an own button
'schedule' => [
'icon' => 'actions-clock',
'title' => 'Schedule publication',
],
];
$event->setData($data);
}
}
Records are indexed by table name and uid of the versioned record. The section is merged into the set of actions the module determines for itself, so only the keys that should differ have to be given:
enabled-falserenders the button greyed out, the way the module does it for missing permissionsvisible-falseremoves the button from the recordicon- identifier of the icon rendered in the buttontitle- title attribute of the buttonurl- renders the action as a link to this URLgroup- identifier of the button group the action is rendered in,customfor actions the module does not know
The module renders the actions
preview
,
qrcode
,
open
,
version
,
expand
,
changes
,
publish
and
remove
itself and knows their icon and title. Every other identifier is rendered from
the payload alone, as a link if an
url
is given and as a button carrying a
data- attribute with the identifier otherwise. The JavaScript of the
declaring extension picks such a button up from there and has to use event
delegation, since the record table is re-rendered whenever the module updates.
The permissions of a record, such as
allowed, are unchanged
and still determine the default state of the module's own actions. Listeners that
modify them therefore keep working as before.