function UserRole::evaluate

Same name and namespace in other branches
  1. 9 core/modules/user/src/Plugin/Condition/UserRole.php \Drupal\user\Plugin\Condition\UserRole::evaluate()
  2. 10 core/modules/user/src/Plugin/Condition/UserRole.php \Drupal\user\Plugin\Condition\UserRole::evaluate()
  3. 11.x core/modules/user/src/Plugin/Condition/UserRole.php \Drupal\user\Plugin\Condition\UserRole::evaluate()

Overrides ConditionInterface::evaluate

File

core/modules/user/src/Plugin/Condition/UserRole.php, line 75

Class

UserRole
Provides a 'User Role' condition.

Namespace

Drupal\user\Plugin\Condition

Code

public function evaluate() {
    if (empty($this->configuration['roles']) && !$this->isNegated()) {
        return TRUE;
    }
    $user = $this->getContextValue('user');
    return (bool) array_intersect($this->configuration['roles'], $user->getRoles());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.