You are here

protected function ViewsBulkOperationsActionProcessor::populateViewResult in Views Bulk Operations (VBO) 8

Populate view result with selected rows.

Parameters

array $list: User selection data.

array $context: Batch API context.

int $current_batch: The current batch index.

1 call to ViewsBulkOperationsActionProcessor::populateViewResult()
ViewsBulkOperationsActionProcessor::populateQueue in src/Service/ViewsBulkOperationsActionProcessor.php
Populate entity queue for processing.

File

src/Service/ViewsBulkOperationsActionProcessor.php, line 387

Class

ViewsBulkOperationsActionProcessor
Defines VBO action processor.

Namespace

Drupal\views_bulk_operations\Service

Code

protected function populateViewResult(array $list, array $context, $current_batch) {
  if (!empty($this->bulkFormData['prepopulated'])) {
    $this->view
      ->setItemsPerPage($this->bulkFormData['batch_size']);
    $this->view
      ->setCurrentPage($current_batch);
    $this->view
      ->build();
    $this->moduleHandler
      ->invokeAll('views_pre_execute', [
      $this->view,
    ]);
    $this->view->query
      ->execute($this->view);
  }
  else {
    if ($this->bulkFormData['current_page']) {
      $this->view
        ->setCurrentPage($this->bulkFormData['current_page']);
    }
    $this->view
      ->build();
    $this->moduleHandler
      ->invokeAll('views_pre_execute', [
      $this->view,
    ]);
    $this->view->query
      ->execute($this->view);

    // Filter result using the $list array.
    foreach ($this->view->result as $delta => $row) {
      $entity = $this->viewDataService
        ->getEntity($row);
      $unset = TRUE;
      foreach ($list as $item) {
        if ($item[1] === $entity
          ->language()
          ->getId() && $item[2] === $entity
          ->getEntityTypeId() && $item[3] === $entity
          ->id()) {
          $unset = FALSE;
          break;
        }
      }
      if ($unset) {
        unset($this->view->result[$delta]);
      }
    }
  }
}