Commit 109dd374 authored by Adam Shepherd's avatar Adam Shepherd
Browse files

Issue #3292173 by snow_ee, gngn, immaculatexavier, AdamPS, tijsdeboeck,...

Issue #3292173 by snow_ee, gngn, immaculatexavier, AdamPS, tijsdeboeck, timohuisman: Roles no longer visible on user_form since 3.1.0 release
parent b55d560a
Loading
Loading
Loading
Loading
+5 −5
Changes for administerusersbyrole.module: 5 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -220,21 +220,21 @@ function administerusersbyrole_user_role_delete(RoleInterface $role) {
 */
function administerusersbyrole_form_user_form_alter(&$form, &$form_state) {
  $user = $form_state->getFormObject()->getEntity();
  $account = Drupal::currentUser();
  $account = \Drupal::currentUser();

  // Allow empty email.
  // @todo Remove when https://www.drupal.org/node/2992848 is fixed.
  if (isset($form['account']['mail']) && !$user->getEmail() && \Drupal::currentUser()->hasPermission('allow empty user mail')) {
  if (isset($form['account']['mail']) && !$user->getEmail() && $account->hasPermission('allow empty user mail')) {
    $form['account']['mail']['#required'] = FALSE;
  }

  if (isset($form['account']['roles']) && administerusersbyrole_user_access($user, 'update', $account)->isAllowed()) {
    $allowed = \Drupal::service('administerusersbyrole.access')->listRoles('role-assign', $account);
    $options = array_intersect_key($form['account']['roles']['#options'], array_flip($allowed));
    if ($options) {
      // Grant access to the allowed roles.
      $form['account']['roles']['#options'] = $options;
    // If there are no available options, hide the role form
    if (empty($options)) {
      $form['account']['roles']['#access'] = FALSE;
      $form['account']['roles']['#access'] = TRUE;
    }
  }
}