You are here

public function ViewsBulkOperationsPassTestAction::executeMultiple in Views Bulk Operations (VBO) 8.3

Same name and namespace in other branches
  1. 8 tests/views_bulk_operations_test/src/Plugin/Action/ViewsBulkOperationsPassTestAction.php \Drupal\views_bulk_operations_test\Plugin\Action\ViewsBulkOperationsPassTestAction::executeMultiple()
  2. 8.2 tests/views_bulk_operations_test/src/Plugin/Action/ViewsBulkOperationsPassTestAction.php \Drupal\views_bulk_operations_test\Plugin\Action\ViewsBulkOperationsPassTestAction::executeMultiple()
  3. 4.0.x tests/views_bulk_operations_test/src/Plugin/Action/ViewsBulkOperationsPassTestAction.php \Drupal\views_bulk_operations_test\Plugin\Action\ViewsBulkOperationsPassTestAction::executeMultiple()

Executes the plugin for an array of objects.

Parameters

array $objects: An array of entities.

Overrides ViewsBulkOperationsActionBase::executeMultiple

1 call to ViewsBulkOperationsPassTestAction::executeMultiple()
ViewsBulkOperationsPassTestAction::execute in tests/views_bulk_operations_test/src/Plugin/Action/ViewsBulkOperationsPassTestAction.php
Executes the plugin.

File

tests/views_bulk_operations_test/src/Plugin/Action/ViewsBulkOperationsPassTestAction.php, line 24

Class

ViewsBulkOperationsPassTestAction
Action for test purposes only.

Namespace

Drupal\views_bulk_operations_test\Plugin\Action

Code

public function executeMultiple(array $nodes) {
  if (!empty($this->context['sandbox'])) {
    $this
      ->messenger()
      ->addMessage(sprintf('Processed %s of %s.', $this->context['sandbox']['processed'], $this->context['sandbox']['total']));
  }

  // Check if the passed view result rows contain the correct nodes.
  if (empty($this->context['sandbox']['result_pass_error'])) {
    $this->view->result = array_values($this->view->result);
    foreach ($nodes as $index => $node) {
      $result_node = $this->view->result[$index]->_entity;
      if ($node
        ->id() !== $result_node
        ->id() || $node
        ->label() !== $result_node
        ->label()) {
        $this->context['sandbox']['result_pass_error'] = TRUE;
      }
    }
  }
  $batch_size = isset($this->context['sandbox']['batch_size']) ? $this->context['sandbox']['batch_size'] : 0;
  $total = isset($this->context['sandbox']['total']) ? $this->context['sandbox']['total'] : 0;
  $processed = isset($this->context['sandbox']['processed']) ? $this->context['sandbox']['processed'] : 0;

  // On last batch display message if passed rows match.
  if ($processed + $batch_size >= $total) {
    if (empty($this->context['sandbox']['result_pass_error'])) {
      $this
        ->messenger()
        ->addMessage('Passed view results match the entity queue.');
    }
  }
}