n Drupal 8 - show role options and hide administrator role in user registration form | CodimTh

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.

 

 

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook