You are here

public function Mail::applyAccountFormProtection in User protect 8

Implements applyAccountFormProtection::isEnabled().

By default, no protection is applied.

Overrides UserProtectionBase::applyAccountFormProtection

File

src/Plugin/UserProtection/Mail.php, line 21

Class

Mail
Protects user's mail address.

Namespace

Drupal\userprotect\Plugin\UserProtection

Code

public function applyAccountFormProtection(array &$form, FormStateInterface $form_state) {
  $build_info = $form_state
    ->getBuildInfo();
  $account = $build_info['callback_object']
    ->getEntity();

  // If for some reason the account has no mail, then don't protect it.
  if ($account
    ->getEmail() && isset($form['account']['mail'])) {
    $form['account']['mail']['#disabled'] = TRUE;
    $form['account']['mail']['#value'] = $account
      ->getEmail();
    return TRUE;
  }
  return FALSE;
}