Skip to content
Snippets Groups Projects

Issue #3213915: Support custom user form modes.

1 file
+ 21
15
Compare changes
  • Side-by-side
  • Inline
+ 21
15
@@ -68,11 +68,18 @@ function roleassign_help($route_name, RouteMatchInterface $route_match) {
function roleassign_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (_roleassign_restrict_access()) {
$user_forms = [
'user_register_form',
'user_form',
'bulk_add_cas_users',
];
/******************************
* Include form id for all user forms,
* including custom form modes.
******************************/
if (($form_state->getBuildInfo()['base_form_id']) == 'user_form') {
$user_forms[] = $form_id;
}
if (in_array($form_id, $user_forms)) {
$roles = array_filter(Role::loadMultiple(), fn(RoleInterface $role) => $role->id() !== RoleInterface::ANONYMOUS_ID);
$roles = array_map(fn(RoleInterface $role) => $role->label(), $roles);
@@ -80,12 +87,21 @@ function roleassign_form_alter(&$form, FormStateInterface $form_state, $form_id)
$sticky_roles = [];
switch ($form_id) {
/******************************
* User Register Form
* User Form
* Bulk Add CAS users
* - Add handling for the CAS module
******************************/
case 'user_register_form':
case 'user_form':
case 'bulk_add_cas_users':
if (\Drupal::service('module_handler')->moduleExists('cas')) {
$form['roles']['#options'] = $assignable_roles;
}
break;
/******************************
* Otherwise assume it's a user form
******************************/
default:
/******************************
* Get currently asssigned roles
******************************/
@@ -162,16 +178,6 @@ function roleassign_form_alter(&$form, FormStateInterface $form_state, $form_id)
$user_form['roles'] = $roles_field;
}
break;
/******************************
* Bulk Add CAS users
* - Add handling for the CAS module
******************************/
case 'bulk_add_cas_users':
if (\Drupal::service('module_handler')->moduleExists('cas')) {
$form['roles']['#options'] = $assignable_roles;
}
break;
}
}
}
Loading