Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- services:
- notifications_log.notifier:
- class: Drupalnotifications_logEventSubscriberNotifierSubscriber
- arguments: ['@plugin.manager.notifier', '@entity_type.manager',
- '@current_user', '@logger.factory']
- tags:
- - { name: event_subscriber }
- plugin.manager.notifier:
- class: Drupalnotifications_logPluginNotifierManager
- parent: default_plugin_manager
- static function getSubscribedEvents() {
- /** @var NotifierManager $notifierManager */
- $notifierManager = Drupal::service('plugin.manager.notifier');
- $events = [];
- foreach ($notifierManager->getNotifierEventNames() as $eventName => $plugin_id) {
- $events[$eventName] = ['onNotification', 0];
- }
- return $events;
- }
- /**
- * {@inheritdoc}
- *
- * We can't return the plugin-based events here, but we set up
- * a response to do that at a later stage
- *
- */
- static function getSubscribedEvents() {
- // Subscribe to kernel request very early.
- $events[KernelEvents::REQUEST][] = ['onRequest', 900];
- return $events;
- }
- /**
- * Add the plugin events at this stage - early in the process.
- *
- * @param GetResponseEvent $event
- */
- public function onRequest(GetResponseEvent $event) {
- // Find every event mentioned in a plugin...
- foreach ($this->notifierManager->getNotifierEventNames() as $eventName => $plugin_id) {
- // Add the event to the dispatcher as a listener, to call my method...
- $this->dispatcher->addListener($eventName, [$this, 'onNotification']);
- }
- }
Add Comment
Please, Sign In to add comment