Incompatible with "Visitors, but administrator approval is required" registration type

Created on 10 October 2019, over 5 years ago
Updated 12 May 2025, 5 days ago

If you wast users to be activated by admins, this module incorrectly sets the user object to 'active' during registration.

You should not be setting it to active in the code below if admin approval is required

function select_registration_roles_form_submit(&$form, \Drupal\Core\Form\FormStateInterface $form_state)
{
    $uid = $form_state->getValues()['uid'];
    $select_roles = $form_state->getValue('select_roles');
    $config = \Drupal::config('select_registration_roles.settings');
    $display_roles = $config->get('select_registration_roles_setby_admin');
    $approval_roles = $config->get('select_registration_roles_admin_approval');
    $user = \Drupal\user\Entity\User::load($uid);
    foreach ($display_roles as $role_id => $role_name) {
        if ($role_name !== 0) {
            if ($role_id === $select_roles) {
                //if approval
                if ($approval_roles[$role_id] === $display_roles[$role_id]) {
                    $user->block();
                    //If not.
                } else {
                    $user->addRole($role_id);
                    $user->activate();
                }
            }
            $user->save();

        }
       }


}
🐛 Bug report
Status

Fixed

Version

1.0

Component

Documentation

Created by

🇬🇧United Kingdom adam clarey

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇰Denmark ressa Copenhagen

    It's not entirely clear what happens, if admin approval for new users is required. Like, who wins -- this module, or Drupal?

    This is from the project page:

    Admin can configure roles need to display on registration form as well as can set roles need for admin approval.

    I just tried, and it looks like a new user is blocked, if:

    • Admin approval is enabled under /admin/config/people/accounts
    • And no roles are selected under "Approval Roles (Select roles that need admin approval.)" under /admin/people/select-registration-roles-setby-admin

    ... which is the expected result.

    But maybe this could be clarified in the project page text? Thanks!

Production build 0.71.5 2024