function single_user_role_form_alter in Single User Role 8
Same name and namespace in other branches
- 7 single_user_role.module \single_user_role_form_alter()
Implements hook_form_alter().
File
- ./
single_user_role.module, line 19 - Single User Role module file.
Code
function single_user_role_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id === 'user_register_form' || $form_id === 'user_form') {
$element =& NestedArray::getValue($form, [
'account',
'roles',
]);
// Make sure this module also works when role_delegation is enabled.
if (isset($form['role_change'])) {
// Making sure administrator also see role field with only one option to
// select.
if ($form['role_change']['#access']) {
$element =& NestedArray::getValue($form, [
'role_change',
'widget',
]);
}
}
_single_user_role_edit_element($element);
// Add custom validation to be called before the core validation.
array_unshift($form['#validate'], 'single_user_role_form_validate');
}
}