If any module doesn't fit your requirement then you can use the below code You can create any custom module and put code in .module file.
function custom_code_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'user_register_form') {
$form['account']['roles']['#title'] = t('User type');
$form['account']['roles']['#access'] = TRUE;
$form['account']['roles']['#required'] = TRUE;
$form['account']['roles']['#type'] = 'select';
foreach ($form['account']['roles']['#options'] as $key => $value) {
if($value == 'administrator') {
unset($form['account']['roles']['#options'][$key]);
}
}
}
}
function custom_code_user_presave(&$edit, $account, $category) {
if (isset($edit['roles'])) {
is_array($edit['roles']) ? '' : $edit['roles'] = array ( $edit['roles'] => $edit['roles'], 2 => '1' );
$edit['roles'] = array_filter($edit['roles']);
}
}
No comments:
Post a Comment