You are here

class ParanoiaDefanger in Paranoia 8

Provides methods to reduce security risks.

Hierarchy

Expanded class hierarchy of ParanoiaDefanger

1 string reference to 'ParanoiaDefanger'
paranoia.services.yml in ./paranoia.services.yml
paranoia.services.yml
1 service uses ParanoiaDefanger
paranoia.defanger in ./paranoia.services.yml
Drupal\paranoia\ParanoiaDefanger

File

src/ParanoiaDefanger.php, line 11

Namespace

Drupal\paranoia
View source
class ParanoiaDefanger {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * A logger instance.
   *
   * @var \Psr\Log\LoggerInterface
   */
  protected $logger;

  /**
   * Constructs a new ParanoiaDefanger.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Psr\Log\LoggerInterface $logger
   *   A logger instance.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, LoggerInterface $logger) {
    $this->entityTypeManager = $entity_type_manager;
    $this->logger = $logger;
  }

  /**
   * Unsets the admin role property of all roles.
   *
   * @see \Drupal\user\AccountSettingsForm::submitForm()
   */
  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(),
      ]);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParanoiaDefanger::$entityTypeManager protected property The entity type manager.
ParanoiaDefanger::$logger protected property A logger instance.
ParanoiaDefanger::unsetAdminRole public function Unsets the admin role property of all roles.
ParanoiaDefanger::__construct public function Constructs a new ParanoiaDefanger.