class ParanoiaDefanger in Paranoia 8
Provides methods to reduce security risks.
Hierarchy
- class \Drupal\paranoia\ParanoiaDefanger
Expanded class hierarchy of ParanoiaDefanger
1 string reference to 'ParanoiaDefanger'
1 service uses ParanoiaDefanger
File
- src/
ParanoiaDefanger.php, line 11
Namespace
Drupal\paranoiaView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ParanoiaDefanger:: |
protected | property | The entity type manager. | |
ParanoiaDefanger:: |
protected | property | A logger instance. | |
ParanoiaDefanger:: |
public | function | Unsets the admin role property of all roles. | |
ParanoiaDefanger:: |
public | function | Constructs a new ParanoiaDefanger. |