You are here

public function ProtectionRule::appliesTo in User protect 8

Returns if this rule applies to the given user.

Parameters

\Drupal\user\UserInterface $user: The user to check.

Return value

bool TRUE if this rule applies to the given user. FALSE otherwise.

Overrides ProtectionRuleInterface::appliesTo

1 call to ProtectionRule::appliesTo()
ProtectionRule::isProtected in src/Entity/ProtectionRule.php
Checks if a given operation on an user should be protected.

File

src/Entity/ProtectionRule.php, line 322

Class

ProtectionRule
Defines the Protection rule entity.

Namespace

Drupal\userprotect\Entity

Code

public function appliesTo(UserInterface $user) {
  switch ($this->protectedEntityTypeId) {
    case 'user':
      return $this->protectedEntityId == $user
        ->id();
    case 'user_role':
      return $user
        ->hasRole($this->protectedEntityId);
  }
  return FALSE;
}