2

I noticed that account.set is the event invoked for a user account.

I want to create an event subscriber which adds a callback invoked when a new user registers on the site. I am not sure whether account.set is the correct event.

Are there other better events for this?

1
  • 2
    I'll try to put a proper answer in later when I have time (if no one else has already done it), but have a read through drupal.org/project/drupal/issues/2551893 for further info. Bottom line is entity CRUD still uses hooks, unless you use one of the contrib modules that add events for them
    – Clive
    Commented Apr 1, 2020 at 18:45

2 Answers 2

3

AccountEvents::SET_USER isn't the event for user registration. Per the docs:

This event allows modules to perform an action whenever the current user is set. The event listener receives an \Drupal\Core\Session\AccountSetEvent instance.

The event is fired when Drupal initializes the user object for the current request, not when new users are created.

For responding to new user creation, you can still use hook_user_insert().

1
  • Aww. I was hoping to write an event subscriber and use Drupal 8's new methods to get the job done. What a pity ;-)
    – Binny
    Commented Apr 2, 2020 at 4:34
3

Aww. I was hoping to write an event subscriber and use Drupal 8's new methods to get the job done. What a pity ;-)

You could using the Hook Event Dispatcher module, see README.md file on how to use.

enter image description here

This module dispatches events for several Drupal core hooks. This allows you to use the D8 Event Subscriber system, instead of the outdated hook system, to react on certain events.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.