Guest User

Untitled

a guest
Dec 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. services:
  2. notifications_log.notifier:
  3. class: Drupalnotifications_logEventSubscriberNotifierSubscriber
  4. arguments: ['@plugin.manager.notifier', '@entity_type.manager',
  5. '@current_user', '@logger.factory']
  6. tags:
  7. - { name: event_subscriber }
  8.  
  9. plugin.manager.notifier:
  10. class: Drupalnotifications_logPluginNotifierManager
  11. parent: default_plugin_manager
  12.  
  13. static function getSubscribedEvents() {
  14. /** @var NotifierManager $notifierManager */
  15. $notifierManager = Drupal::service('plugin.manager.notifier');
  16.  
  17. $events = [];
  18. foreach ($notifierManager->getNotifierEventNames() as $eventName => $plugin_id) {
  19. $events[$eventName] = ['onNotification', 0];
  20. }
  21.  
  22. return $events;
  23. }
  24.  
  25. /**
  26. * {@inheritdoc}
  27. *
  28. * We can't return the plugin-based events here, but we set up
  29. * a response to do that at a later stage
  30. *
  31. */
  32. static function getSubscribedEvents() {
  33. // Subscribe to kernel request very early.
  34. $events[KernelEvents::REQUEST][] = ['onRequest', 900];
  35.  
  36. return $events;
  37. }
  38.  
  39. /**
  40. * Add the plugin events at this stage - early in the process.
  41. *
  42. * @param GetResponseEvent $event
  43. */
  44. public function onRequest(GetResponseEvent $event) {
  45. // Find every event mentioned in a plugin...
  46. foreach ($this->notifierManager->getNotifierEventNames() as $eventName => $plugin_id) {
  47. // Add the event to the dispatcher as a listener, to call my method...
  48. $this->dispatcher->addListener($eventName, [$this, 'onNotification']);
  49. }
  50. }
Add Comment
Please, Sign In to add comment