PackageInitializationEvent

New in version 13.0

The PSR-14 event \TYPO3\CMS\Core\Package\Event\PackageInitializationEvent 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:setup command.

The main component dispatching the event is the \TYPO3\CMS\Core\Package\PackageActivationService .

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 addStorageEntry() method. This is also used by the Core listeners to store their result.

Example

EXT:my_extension/Classes/Package/EventListener/MyEventListener.php
<?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');
        }
    }
}
Copied!

New in version 13.0

API

class PackageInitializationEvent
Fully qualified name
\TYPO3\CMS\Core\Package\Event\PackageInitializationEvent

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.

getExtensionKey ( )
Returns
string
getPackage ( )
Returns
\TYPO3\CMS\Core\Package\PackageInterface
getContainer ( )
Returns
?\Psr\Container\ContainerInterface
getEmitter ( )
Returns
?object
hasStorageEntry ( string $identifier)
param $identifier

the identifier

Returns
bool
getStorageEntry ( string $identifier)
param $identifier

the identifier

Returns
\TYPO3\CMS\Core\Package\PackageInitializationResult
addStorageEntry ( string $identifier, ?mixed $data)
param $identifier

the identifier

param $data

the data

removeStorageEntry ( string $identifier)
param $identifier

the identifier