public function UserHasRole::process in Business Rules 8
Same name and namespace in other branches
- 2.x src/Plugin/BusinessRulesCondition/UserHasRole.php \Drupal\business_rules\Plugin\BusinessRulesCondition\UserHasRole::process()
Process the condition.
Parameters
\Drupal\business_rules\ConditionInterface $condition: The configured condition.
\Drupal\business_rules\Events\BusinessRulesEvent $event: The event that has triggered the condition.
Return value
bool Boolean value that indicates if the condition is true.
Overrides BusinessRulesConditionPlugin::process
File
- src/
Plugin/ BusinessRulesCondition/ UserHasRole.php, line 74
Class
- UserHasRole
- Class UserHasRole.
Namespace
Drupal\business_rules\Plugin\BusinessRulesConditionCode
public function process(ConditionInterface $condition, BusinessRulesEvent $event) {
$roles = $condition
->getSettings('roles');
$criteria = $condition
->getSettings('criteria');
/** @var \Drupal\user\Entity\User $current_user */
$current_user = $this->util->container
->get('current_user');
$user_roles = array_values($current_user
->getRoles());
$result = FALSE;
if (is_array($roles) && is_array($user_roles)) {
if ($criteria == 'all') {
$result = count(array_intersect($roles, $user_roles)) == count($roles);
}
elseif ($criteria == 'one') {
$result = !empty(array_intersect($user_roles, $roles));
}
}
return $result;
}