You are here

public function ParanoiaDefanger::unsetAdminRole in Paranoia 8

Unsets the admin role property of all roles.

See also

\Drupal\user\AccountSettingsForm::submitForm()

File

src/ParanoiaDefanger.php, line 45

Class

ParanoiaDefanger
Provides methods to reduce security risks.

Namespace

Drupal\paranoia

Code

public function unsetAdminRole() {

  /** @var \Drupal\user\RoleStorageInterface $role_storage */
  $role_storage = $this->entityTypeManager
    ->getStorage('user_role');
  $admin_roles = $role_storage
    ->getQuery()
    ->condition('is_admin', TRUE)
    ->execute();
  foreach ($admin_roles as $rid) {
    $role = $role_storage
      ->load($rid);
    $role
      ->setIsAdmin(FALSE)
      ->save();
    $this->logger
      ->notice('Removed the admin role property from the %title role.', [
      '%title' => $role
        ->label(),
    ]);
  }
}