Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By roric32 on
I have a class which implements EventSubscriberInterface. It is registered in the services.yml of my module. From a function in this class, I want to be able to add a different class implementing EventSubscriberInterface as a subscriber.
I've tried using the following:
$dispatch = new EventDispatcher();
$dispatch->addSubscriber(new MyOtherClass());
That doesn't give me any errors, but it doesn't seem to do anything.
Can anybody help me?