[Drupal] Service dependency injection in a service type class

The code

    # Your service class
    class: Drupal\my_module\Entity\EventSubscriber\MyModuleSubscriber

    # Add your services to load here in the array
    arguments: ['@current_user']

      # For this example, I am making an event subscriber class
      - { name: event_subscriber }
currentUser = $current_user;

  static function getSubscribedEvents() {
    // Stuff related to events subscribing in Drupal
    $events[KernelEvents::REQUEST][] = ['kernel_request'];
    return $events;

   * @param GetResponseEvent $event
  public function kernel_request(Event $event) {
    // Do stuff here, using $this->currentUser


Additional Information

Published by Dakwamine

Dakwamine, alias Quang-Minh Dang, né en 1987 en région parisienne. Un type sympa, pas bavard et pragmatique.