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

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 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\CMS\Core\Attribute\AsEventListener has been introduced to tag a PHP class as an event listener. Alternatively, you can also register an event listener via the Configuration/Services.yaml file. Have a look into the section Implementing an event listener in your extension.

API

class 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()
Return type

string

getPackage()
Return type

TYPO3\CMS\Core\Package\PackageInterface

getContainer()
Return type

Psr\Container\ContainerInterface

getEmitter()
Return type

object

hasStorageEntry(string $identifier)
Parameters
  • $identifier (string) -- the identifier

Return type

bool

getStorageEntry(string $identifier)
Parameters
  • $identifier (string) -- the identifier

Return type

TYPO3\CMS\Core\Package\PackageInitializationResult

addStorageEntry(string $identifier, mixed $data)
Parameters
  • $identifier (string) -- the identifier

  • $data (mixed) -- the data

removeStorageEntry(string $identifier)
Parameters
  • $identifier (string) -- the identifier