You are here

public function GroupHasUserCondition::process in Business Rules 8

Same name and namespace in other branches
  1. 2.x modules/br_group/src/Plugin/BusinessRulesCondition/GroupHasUserCondition.php \Drupal\br_group\Plugin\BusinessRulesCondition\GroupHasUserCondition::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/GroupHasUserCondition.php, line 111

Class

GroupHasUserCondition
Class GroupHasUserCondition.

Namespace

Drupal\br_group\Plugin\BusinessRulesCondition

Code

public function process(ConditionInterface $condition, BusinessRulesEvent $event) {
  $variables = $event
    ->getArgument('variables');
  $group_id = $condition
    ->getSettings('group_id');
  $group_id = $this
    ->processVariables($group_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);
  if ($member instanceof GroupMembership) {
    $result = TRUE;
  }
  else {
    $result = FALSE;
  }
  return $result;
}