You are here

public function Roles::applyAccountFormProtection in User protect 8

Implements applyAccountFormProtection::isEnabled().

By default, no protection is applied.

Overrides UserProtectionBase::applyAccountFormProtection

File

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

Class

Roles
Protects user's roles.

Namespace

Drupal\userprotect\Plugin\UserProtection

Code

public function applyAccountFormProtection(array &$form, FormStateInterface $form_state) {

  // Make sure this module also works when role_delegation is enabled.
  $applied = FALSE;
  if (isset($form['role_change']['widget'])) {
    $form['role_change']['widget']['#disabled'] = TRUE;
    $applied = TRUE;
  }
  if (isset($form['account']['roles'])) {
    $form['account']['roles']['#disabled'] = TRUE;
    $applied = TRUE;
  }
  return $applied;
}