TYPO3: Why is my PSR-14 event listener registration not working?

Viewed 916

I want to replace my old signal registration through a PSR-14 event listener registration. So I have removed the following from my ext_localconf.php:

ext_localconf.php

...
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
$signalSlotDispatcher->connect(
    \TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class,
    'afterExtensionInstall',
    \My\Example\Slots\InstallUtility::class,
    'afterExtensionInstall'
);
...

Furthermore, I have created the following file:

Configuration/Services.yaml

services:
  My\Example\Slots\InstallUtility:
    tags:
      - name: event.listener
        identifier: 'afterExtensionInstall'
        event: TYPO3\CMS\Core\Package\Event\AfterPackageActivationEvent

After that I have added an invoke function to My\Example\Slots\InstallUtility:

namespace My\Example\Slots;

use TYPO3\CMS\Core\Package\Event\AfterPackageActivationEvent;

class InstallUtility
{
    /**
     * @param AfterPackageActivationEvent $event
     */
    public function __invoke(AfterPackageActivationEvent $event): void
    {
        \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump('event got triggered'); die();
    }

    ...
}

But this is not working. If deactivate my extension via extension manager and then reactivate it again, nothing happens.

Did I miss something here?

1 Answers

I had the same problem. Solution was as follows:

  • Run composer dump-autoload after setting up your configuration in Configuration\Services.yaml
  • Clear the cache via Admin Tools > Maintenance > Flush TYPO3 and PHP Cache

You can check that it works in System > Configuration > Event Listeners (PSR-14)

Related