You are here

public function ViewsBulkOperationsViewData::getTotalResults in Views Bulk Operations (VBO) 4.0.x

Same name and namespace in other branches
  1. 8.3 src/Service/ViewsBulkOperationsViewData.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsViewData::getTotalResults()
  2. 8 src/Service/ViewsBulkOperationsViewData.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsViewData::getTotalResults()
  3. 8.2 src/Service/ViewsBulkOperationsViewData.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsViewData::getTotalResults()

Get the total count of results on all pages.

Parameters

bool $clear_on_exposed: Are we clearing selection on exposed filters change?

Return value

int The total number of results this view displays.

Overrides ViewsBulkOperationsViewDataInterface::getTotalResults

File

src/Service/ViewsBulkOperationsViewData.php, line 185

Class

ViewsBulkOperationsViewData
Gets Views data needed by VBO.

Namespace

Drupal\views_bulk_operations\Service

Code

public function getTotalResults($clear_on_exposed = FALSE) {
  $total_results = NULL;
  if (!$clear_on_exposed && !empty($this->view
    ->getExposedInput())) {
    if ($pager = $this->view
      ->getPager()) {
      $pager_options = $pager->options;
      $pager_options['total_items'] = $pager
        ->getTotalItems();
    }

    // Execute the view without exposed input set.
    $view = Views::getView($this->view
      ->id());
    $view
      ->setDisplay($this->view->current_display);

    // If there are any arguments, pass them through.
    if (!empty($this->view->args)) {
      $view
        ->setArguments($this->view->args);
    }
    $view->get_total_rows = TRUE;

    // We have to set exposed input to some value here, empty
    // value will be overwritten with query params by Views so
    // setting an empty array wouldn't work.
    $pager = $view
      ->getPager();
    $view
      ->setExposedInput([
      '_views_bulk_operations_override' => TRUE,
    ]);
  }
  else {
    $view = $this->view;
  }

  // Execute the view if not already executed.
  $view
    ->execute();
  if (!empty($view->pager->total_items)) {
    $total_results = $view->pager->total_items;
  }
  elseif (!empty($view->total_rows)) {
    $total_results = $view->total_rows;
  }
  if (!empty($pager_options) && !empty($pager_options['id'])) {
    $this->pagerManager
      ->createPager($pager_options['total_items'], $pager_options['items_per_page'], $pager_options['id']);
  }
  return $total_results;
}