public function DataComparison::process in Business Rules 2.x
Same name and namespace in other branches
- 8 src/Plugin/BusinessRulesCondition/DataComparison.php \Drupal\business_rules\Plugin\BusinessRulesCondition\DataComparison::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/ DataComparison.php, line 112
Class
- DataComparison
- Class DataComparison.
Namespace
Drupal\business_rules\Plugin\BusinessRulesConditionCode
public function process(ConditionInterface $condition, BusinessRulesEvent $event) {
/** @var \Drupal\Core\Entity\Entity $entity */
$field = $condition
->getSettings('field');
$operator = $condition
->getSettings('operator');
$variables = $event
->getArgument('variables');
$values_to_compare = explode(chr(10), $condition
->getSettings('value_to_compare'));
$values_to_compare = $this
->processInternalVariables($values_to_compare, $variables);
$data_to_compare = $condition
->getSettings('data_to_compare');
if ($data_to_compare == self::CURRENT_DATA) {
$entity = $event
->getArgument('entity');
}
elseif ($data_to_compare == self::ORIGINAL_DATA) {
$entity = $event
->getArgument('entity_unchanged');
}
$values = $entity
->get($field)
->getValue();
if (count($values)) {
foreach ($values as $value) {
foreach ($values_to_compare as $compare) {
return $this
->compare($value, $compare, $operator);
}
}
}
elseif ($operator == 'empty') {
foreach ($values_to_compare as $compare) {
return $this
->compare([
'value' => '',
], $compare, $operator);
}
}
return FALSE;
}