You are here

function user_permissions_form_alter in User Permissions 8

Same name and namespace in other branches
  1. 5 user_permissions.module \user_permissions_form_alter()

Implements hook_form_alter().

Alter user list page.

File

./user_permissions.module, line 54
Module file for user_permissions.

Code

function user_permissions_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if (strpos($form_id, 'views_form_user_admin_people_page') !== FALSE) {

    // Remove _user_role_N roles from the Add/Remove role to the selected users.
    // @link /admin/people
    if (!empty($form['header']['user_bulk_form']['action']['#options'])) {
      $options =& $form['header']['user_bulk_form']['action']['#options'];
      $operations = [
        'user_add_role_action.',
        'user_remove_role_action.',
      ];
      foreach ($operations as $operation) {
        if ($opts = preg_grep('/.*?(_user_role_\\d+$)/', array_keys($options))) {
          foreach ($opts as $action) {
            unset($options[$action]);
          }
        }
      }
    }
  }

  // Remove _user_role_N roles from exposed filter on user list.
  // @link /admin/people
  if (strpos($form_id, 'views_exposed_form') !== FALSE) {
    if (is_array($form['role']['#options'])) {

      // Removes _user_role_N roles from the roles user filter.
      // @link /admin/people page.
      user_permissions_array_filter_roles($form['role']['#options']);
    }
  }
}