Skip to main content
added 364 characters in body
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

Your code is subscribing to a kernel event KernelEvents::REQUEST dispatched on every request.

TryBut you want to subscribe to the custom event 'mymodule_user_login'. The array value is the callback method, not the event name

static function getSubscribedEvents() {
    $events['mymodule_user_login'][] = ['onUserLoginCallback', 1];
    return $events;
}

which receives the custom event object, not a core event:

public function onUserLoginCallback(MyEvent $event) {
  ...
}

BTW the dispatching code is deprecated. In Drupal 9 or higher swap both arguments:

$event_dispatcher->dispatch($event, 'mymodule_user_login');

See https://symfony.com/blog/new-in-symfony-4-3-simpler-event-dispatching

Your code is subscribing to a kernel event dispatched on every request.

Try

static function getSubscribedEvents() {
    $events['mymodule_user_login'][] = ['onUserLoginCallback', 1];
    return $events;
}

BTW the dispatching code is deprecated. In Drupal 9 or higher swap both arguments:

$event_dispatcher->dispatch($event, 'mymodule_user_login');

Your code is subscribing to a kernel event KernelEvents::REQUEST dispatched on every request.

But you want to subscribe to the custom event 'mymodule_user_login'. The array value is the callback method, not the event name

static function getSubscribedEvents() {
    $events['mymodule_user_login'][] = ['onUserLoginCallback', 1];
    return $events;
}

which receives the custom event object, not a core event:

public function onUserLoginCallback(MyEvent $event) {
  ...
}

BTW the dispatching code is deprecated. In Drupal 9 or higher swap both arguments:

$event_dispatcher->dispatch($event, 'mymodule_user_login');

See https://symfony.com/blog/new-in-symfony-4-3-simpler-event-dispatching

Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

Your code is subscribing to a kernel event dispatched on every request.

Try

static function getSubscribedEvents() {
    $events['mymodule_user_login'][] = ['onUserLoginCallback', 1];
    return $events;
}

BTW the dispatching code is deprecated. In Drupal 9 or higher swap both arguments:

$event_dispatcher->dispatch($event, 'mymodule_user_login');