public function CheckViewResultCount::process in Business Rules 8
Same name and namespace in other branches
- 2.x src/Plugin/BusinessRulesCondition/CheckViewResultCount.php \Drupal\business_rules\Plugin\BusinessRulesCondition\CheckViewResultCount::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/ CheckViewResultCount.php, line 66
Class
- CheckViewResultCount
- Class CheckViewResultCount.
Namespace
Drupal\business_rules\Plugin\BusinessRulesConditionCode
public function process(ConditionInterface $condition, BusinessRulesEvent $event) {
// Get settings.
$defined_view = $condition
->getSettings('view');
$args = $condition
->getSettings('arguments');
$comparison = $condition
->getSettings('comparison');
$event_variables = $event
->getArgument('variables');
// Process settings.
$defined_view = explode(':', $defined_view);
$view_id = $defined_view[0];
$display = $defined_view[1];
$args = explode(chr(10), $args);
$args = array_map('trim', $args);
$args = array_filter($args, 'strlen');
// Process variables.
foreach ($args as $key => $value) {
$args[$key] = $this
->processVariables($value, $event_variables);
}
// Execute view.
$view = Views::getView($view_id);
$view
->setArguments($args);
$view
->setDisplay($display);
$view
->preExecute();
$view
->build();
if ($view
->execute()) {
$view_result = $view->result;
$result = count($view_result);
}
else {
$result = 0;
}
// Check the condition.
if ($result >= $comparison) {
return TRUE;
}
else {
return FALSE;
}
}