You are here

function administerusersbyrole_form_user_form_alter in Administer Users by Role 8.2

Same name and namespace in other branches
  1. 8.3 administerusersbyrole.module \administerusersbyrole_form_user_form_alter()

Implements hook_form_FORM_ID_alter().

File

./administerusersbyrole.module, line 180

Code

function administerusersbyrole_form_user_form_alter(&$form, &$form_state) {
  $user = $form_state
    ->getFormObject()
    ->getEntity();
  $account = Drupal::currentUser();

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