public function UserHasRoleGroupCondition::process in Business Rules 2.x
Same name and namespace in other branches
- 8 modules/br_group/src/Plugin/BusinessRulesCondition/UserHasRoleGroupCondition.php \Drupal\br_group\Plugin\BusinessRulesCondition\UserHasRoleGroupCondition::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
- modules/
br_group/ src/ Plugin/ BusinessRulesCondition/ UserHasRoleGroupCondition.php, line 119
Class
- UserHasRoleGroupCondition
- Class UserHasRoleGroupCondition.
Namespace
Drupal\br_group\Plugin\BusinessRulesConditionCode
public function process(ConditionInterface $condition, BusinessRulesEvent $event) {
$variables = $event
->getArgument('variables');
$group_id = $condition
->getSettings('group_id');
$group_id = $this
->processVariables($group_id, $variables);
$role_id = $condition
->getSettings('role_id');
$role_id = $this
->processVariables($role_id, $variables);
$user_key = $condition
->getSettings('user_key');
$user_name = $condition
->getSettings('user_name');
$user_name = $this
->processVariables($user_name, $variables);
$user_id = $condition
->getSettings('user_id');
$user_id = $this
->processVariables($user_id, $variables);
if ($user_key == 'userid') {
$user = User::load($user_id);
}
else {
$id = $this->util->container
->get('entity_type.manager')
->getStorage('user')
->getQuery()
->condition('name', $user_name)
->execute();
$user = User::load(array_values($id)[0]);
}
$group = Group::load($group_id);
$member = $group
->getMember($user);
$result = FALSE;
if ($member instanceof GroupMembership) {
$roles = $member
->getRoles();
$roles_keys = array_keys($roles);
$group_type_id = $group
->getGroupType()
->id();
$role_id = substr($role_id, 0, strlen("{$group_type_id}-")) == "{$group_type_id}-" ? $role_id : "{$group_type_id}-{$role_id}";
if (in_array($role_id, $roles_keys)) {
$result = TRUE;
}
}
return $result;
}