You are here

public function Status::applyAccountFormProtection in User protect 8

Implements applyAccountFormProtection::isEnabled().

By default, no protection is applied.

Overrides UserProtectionBase::applyAccountFormProtection

File

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

Class

Status
Protects user's status.

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 (isset($form['account']['status'])) {
    $form['account']['status']['#disabled'] = TRUE;
    $form['account']['status']['#value'] = $account
      ->isActive();
    return TRUE;
  }
  return FALSE;
}