public function ProtectionRule::isProtected in User protect 8
Checks if a given operation on an user should be protected.
Parameters
\Drupal\user\UserInterface $user: The user object to check access for.
string $op: The operation that is to be performed on $user.
\Drupal\Core\Session\AccountInterface $account: The account trying to access the entity.
Return value
bool TRUE if the operation should be protected. FALSE if the operation is not protected by this rule.
Overrides ProtectionRuleInterface::isProtected
File
- src/
Entity/ ProtectionRule.php, line 346
Class
- ProtectionRule
- Defines the Protection rule entity.
Namespace
Drupal\userprotect\EntityCode
public function isProtected(UserInterface $user, $op, AccountInterface $account) {
// First check if this protection rule is applyable to the given user.
if (!$this
->appliesTo($user)) {
// Not applyable. The operation is not protected by this rule.
return FALSE;
}
// Check if the asked operation is equal to a protection plugin name
// and if so, check if that protection plugin is enabled for this
// rule.
if ($this
->hasProtection($op)) {
// Protection enabled. The operation is protected by this rule.
return TRUE;
}
foreach ($this
->getProtections() as $protection) {
if ($protection
->isEnabled()) {
if ($protection
->isProtected($user, $op, $account)) {
// The plugin says the operation is not permitted.
return TRUE;
}
}
}
// In all other cases, the operation is not protected by this rule.
return FALSE;
}