Hot answers tagged


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. ...


This is the way I do it: // Get actual user role. $current_user_roles = \Drupal::currentUser()->getRoles(); // Check if user is not admin. if (!in_array('administrator', $current_user_roles)) { // Check if user is an admin. if (in_array('administrator', $current_user_roles)) {

Only top voted, non community-wiki answers of a minimum length are eligible