You are here

public function LoopThroughViewResult::execute in Business Rules 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/BusinessRulesAction/LoopThroughViewResult.php \Drupal\business_rules\Plugin\BusinessRulesAction\LoopThroughViewResult::execute()

Execute the action.

Parameters

\Drupal\business_rules\ActionInterface $action: The configured action.

\Drupal\business_rules\Events\BusinessRulesEvent $event: The event that has triggered the action.

Return value

array The render array to be showed on debug block.

Overrides BusinessRulesActionPlugin::execute

File

src/Plugin/BusinessRulesAction/LoopThroughViewResult.php, line 333

Class

LoopThroughViewResult
Class LoopThroughViewResult.

Namespace

Drupal\business_rules\Plugin\BusinessRulesAction

Code

public function execute(ActionInterface $action, BusinessRulesEvent $event) {

  /** @var \Drupal\business_rules\VariablesSet $event_variables */
  $event_variables = $event
    ->getArgument('variables');
  $view_variable = $event_variables
    ->getVariable($action
    ->getSettings('variable'));
  $action_items = $action
    ->getSettings('items');

  // Execute action items.
  foreach ($view_variable
    ->getValue() as $row) {

    // Append each field as variable.
    foreach ($row as $field => $value) {
      $varObj = new VariableObject($view_variable
        ->getId() . '->' . $field, $value, $view_variable
        ->getType());
      $event_variables
        ->append($varObj);
    }

    // Process items.
    if (!empty($action_items)) {
      $items = BusinessRulesItemObject::itemsArrayToItemsObject($action_items);
      $this->processor
        ->processItems($items, $event, $action
        ->id());
    }
  }
}