How is it possible to use Symfony\Component\EventDispatcher\EventSubscriberInterface
to implement a subscriber-class, listening for events dispatched by TYPO3s PSR-14 EventDispatcher?
Let's see an example by using symfony/workflow
for a TYPO3 extension, which works great until it comes to events. Because of typo3/symfony-psr-event-dispatcher-adapter
, the TYPO3 default EventDispatcher can be smoothly added to the Workflow
class. So far so good.
Now I've several problems:
Problem 1: The event-names such as 'workflow.myname.leave'
The events dispatched by Workflow
using a string name, instead of a FQCN like all other events dispatched in the TYPO3 life-cycle. This makes it impossible to use the common way of EventListeners registered inside the services.yaml
, because the configuration requires a FQCN of the event-class.
# this will not work because the "event" needs to be a FQCN
Vendor\MyExt\EventListener\MyWorkflowEventListener:
tags:
- name: event.listener
identifier: 'vendor-myext/MyWorkflowEventListener'
event: 'workflow.myname.leave'
method: 'onLeave'
Problem 2: Trying to use an EventSubscriber
The doc recomments an EventSubscriber. IMO using an EventSubscriber (Symfony\Component\EventDispatcher\EventSubscriberInterface
) would also solve problem #1, because the configuration of events is defined as key-value array inside getSubscribedEvents()
. (BTW this seems to be also much easier for lots of events like in this case of workflow-events, because one class can be responsible handling multiple "similar" events and will not mess-up the services.yaml
).
Also the Symfony doc says, that implementing this interface while autowire
and autoconfigure
is set to true
will be enough; the EventSubscriber should be available and listening. Maybe this is true in a plain Symfony environment, but it seems not in a context of TYPO3. Unfortunately I can't figure out why (the subscriber classes doesn't show up inside EventDispatcher->ListenerProvider->listeners array).
How to continue here?