PackageInitializationEvent
New in version 13.0
The PSR-14 event \TYPO3\
allows listeners to execute custom functionality after an extension has been
activated.
The event is being dispatched at several places, where extensions get activated. Those are, for example:
- on extension installation by the extension manager
- on calling the
typo3 extension:
command.setup
The main component dispatching the event is the
\TYPO3\
.
Developers are able to listen to the new event before or after the TYPO3 Core
listeners have been executed, using before
and after
in the
listener registration. All listeners are able to store arbitrary data
in the event using the add
method. This is also used
by the Core listeners to store their result.
Example
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Package\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Package\Event\PackageInitializationEvent;
use TYPO3\CMS\Core\Package\Initialization\ImportExtensionDataOnPackageInitialization;
#[AsEventListener(
identifier: 'my-extension/package-initialization',
after: ImportExtensionDataOnPackageInitialization::class,
)]
final readonly class MyEventListener
{
public function __invoke(PackageInitializationEvent $event): void
{
if ($event->getExtensionKey() === 'my_extension') {
$event->addStorageEntry(__CLASS__, 'my result');
}
}
}
New in version 13.0
The PHP attribute \TYPO3\
has been
introduced to tag a PHP class as an event listener. Alternatively, you can also
register an event listener via the Configuration/
file. Have
a look into the section Implementing an event listener in your extension.
API
- class PackageInitializationEvent
-
- Fully qualified name
-
\TYPO3\
CMS\ Core\ Package\ Event\ Package Initialization Event
Event that is triggered after a package has been activated (or required in composer mode), allowing listeners to execute initialization tasks, such as importing static data.
- getStorageEntry ( string $identifier)
-
- param $identifier
-
the identifier
- Returns
-
\TYPO3\
CMS\ Core\ Package\ Package Initialization Result