You are here

private function Table::fixCounterFields in Views Aggregator Plus 8

Set correct counter field order after sorting.

1 call to Table::fixCounterFields()
Table::preRender in src/Plugin/views/style/Table.php
Note that this class being a views_plugin, rather than a views_handler, it does not have a post_execute() function.

File

src/Plugin/views/style/Table.php, line 1442

Class

Table
Style plugin to render each item as a row in a table.

Namespace

Drupal\views_aggregator\Plugin\views\style

Code

private function fixCounterFields() {

  // Get the list of counter fields
  $fields = [];
  foreach ($this->view->field as $field_name => $properties) {
    if ($properties->pluginId == 'counter') {
      $fields[$field_name] = $properties->options['counter_start'];
    }
  }

  // If we use a pager - do not reset the counter on each page.
  $counter_offset = 0;
  if ($this->view
    ->usePager()) {
    $page_items = $this->view->pager
      ->getItemsPerPage();
    $current_page = $this->view->pager->current_page;
    $counter_offset = $current_page * $page_items;
  }

  // Update fields and use the offset of previous pages.
  foreach ($fields as $field_name => $start) {
    foreach ($this->view->result as $key => $value) {
      $this->rendered_fields[$key][$field_name] = $start++ + $counter_offset;
    }
  }
}