You are here

public function ViewsBulkOperationsActionProcessor::getPageList in Views Bulk Operations (VBO) 8.2

Same name and namespace in other branches
  1. 8.3 src/Service/ViewsBulkOperationsActionProcessor.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessor::getPageList()
  2. 4.0.x src/Service/ViewsBulkOperationsActionProcessor.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessor::getPageList()

Get full list of items from a specific view page.

Parameters

int $page: Results page number.

Return value

array Array of result data arrays.

Overrides ViewsBulkOperationsActionProcessorInterface::getPageList

1 call to ViewsBulkOperationsActionProcessor::getPageList()
ViewsBulkOperationsActionProcessor::executeProcessing in src/Service/ViewsBulkOperationsActionProcessor.php
Helper function for processing results from view data.

File

src/Service/ViewsBulkOperationsActionProcessor.php, line 164

Class

ViewsBulkOperationsActionProcessor
Defines VBO action processor.

Namespace

Drupal\views_bulk_operations\Service

Code

public function getPageList($page) {
  $list = [];
  $this->viewDataService
    ->init($this->view, $this->view
    ->getDisplay(), $this->bulkFormData['relationship_id']);

  // Set exposed filters and pager parameters.
  if (!empty($this->bulkFormData['exposed_input'])) {
    $this->view
      ->setExposedInput($this->bulkFormData['exposed_input']);
  }
  $this->view
    ->setItemsPerPage($this->bulkFormData['batch_size']);
  $this->view
    ->setCurrentPage($page);
  $this->view
    ->build();
  $offset = $this->bulkFormData['batch_size'] * $page;

  // If the view doesn't start from the first result,
  // move the offset.
  if ($pager_offset = $this->view->pager
    ->getOffset()) {
    $offset += $pager_offset;
  }
  $this->view->query
    ->setLimit($this->bulkFormData['batch_size']);
  $this->view->query
    ->setOffset($offset);
  $this->moduleHandler
    ->invokeAll('views_pre_execute', [
    $this->view,
  ]);
  $this->view->query
    ->execute($this->view);
  $base_field = $this->view->storage
    ->get('base_field');
  foreach ($this->view->result as $row) {
    $entity = $this->viewDataService
      ->getEntity($row);

    // We don't need entity label here.
    $list[] = [
      $row->{$base_field},
      $entity
        ->language()
        ->getId(),
      $entity
        ->getEntityTypeId(),
      $entity
        ->id(),
    ];
  }
  return $list;
}