Feature: #97201 - PSR-14 event for modifying new content element wizard items
See forge#97201
Description
A new PSR-14 event \TYPO3\
has been introduced which serves as a more powerful and flexible alternative
for the now removed hook
$GLOBALS
.
The event is called after TYPO3 has already prepared the wizard items,
defined in TSconfig (mod.
).
The event allows listeners to modify any available wizard item as well as adding new ones. It's therefore possible for the listeners to e.g. change the configuration, the position or to remove existing items altogether.
Following methods are available:
Method | Parameters | Description |
---|---|---|
getWizardItems() | Returns all available wizard items. | |
setWizardItems() | $wizard | Updates / overwrites the available wizard items. |
hasWizardItem() | $identifier | Whether a wizard item with the $identifier
exists. |
getWizardItem() | $identifier | Returns the wizard item with the
$identifier or null if it does not
exist. |
setWizardItem() | $identifier
$configuration
$position | Add a new wizard item with the identifier
and the $configuration at the defined
$position . $position is an array .
Allowed values are before => <identifier> and
after => <identifier> . Can also be used to
modify or relocate existing items. |
removeWizardItem() | $identifier | Removes a wizard item with the $identifier |
getPageInfo() | Provides information about the current page making use of the wizard. | |
getColPos() | Provides information about the column position of the button that triggered the wizard. | |
getSysLanguage() | Provides information about the language used while triggering the wizard. | |
getUidPid() | Provides information about the element to position the new element after (uid) or into (pid). |
Example
Registration of the event in your extension's Services.
:
MyVendor\MyPackage\Frontend\MyEventListener:
tags:
- name: event.listener
identifier: 'my-package/backend/modify-wizard-items'
The corresponding event listener class:
use TYPO3\CMS\Backend\Controller\Event\ModifyNewContentElementWizardItemsEvent;
class MyEventListener {
public function __invoke(
ModifyNewContentElementWizardItemsEvent $event
): void
{
// Add a new wizard item after "textpic"
$event->setWizardItem(
'my_element',
[
'iconIdentifier' => 'icon-my-element',
'title' => 'My element',
'description' => 'My element description',
'tt_content_defValues' => [
'CType' => 'my_element'
],
],
['after' => 'common_textpic']
);
}
}
Impact
The main advantages of the new PSR-14 event are the object-oriented approach as well as the built-in convenience features, like relocating of the wizard items.