Check for new non admin-created users is wrong

Created on 9 December 2024, about 2 months ago

Problem/Motivation

// Only proceed if the user is not an admin user ($account->isNew() will
  // return FALSE here, so we don't check it):
  if (in_array('administrator', $account->getRoles())) {
    return;
  }

is wrong, not only administrators can create new user accounts!

Here are some examples from similar modules:
https://git.drupalcode.org/project/registration_role/-/blob/8.x-1.x/regi...
https://git.drupalcode.org/project/redirect_after_registration/-/blob/1....

I'd vote for a simple solution:

\Drupal::currentUser()->isAnonymous()

Please note that we check for the current user, not the user account that was created.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024