Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

Code snippet that can be used to show role options to users and hide administrator role in user registration form in Drupal 8.

<?php

/**
 * @param $form
 * @param $form_state
 * @param $form_id
 */
function mymodule_form_user_register_form_alter(&$form, &$form_state, $form_id)
{
  unset($form['account']['roles']['#options']['administrator']);
  $form['account']['roles']['#access'] = TRUE;
}

With this snippet:

users with the permission of 'administer users' can assign roles on the user registration form.

Hide the 'administrator' role for your users.

 

 

Comments

Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon