public function Counter::get_value

Overrides Drupal\views\Plugin\views\field\FieldPluginBas::get_value()

Overrides FieldPluginBase::get_value

File

drupal/core/modules/views/lib/Drupal/views/Plugin/views/field/Counter.php, line 48
Definition of Drupal\views\Plugin\views\field\Counter.

Class

Counter
Field handler to show a counter of the current row.

Namespace

Drupal\views\Plugin\views\field

Code

public function get_value($values, $field = NULL) {

  // Note:  1 is subtracted from the counter start value below because the
  // counter value is incremented by 1 at the end of this function.
  $count = is_numeric($this->options['counter_start']) ? $this->options['counter_start'] - 1 : 0;
  $pager = $this->view->pager;

  // Get the base count of the pager.
  if ($pager
    ->use_pager()) {
    $count += $pager
      ->get_items_per_page() * $pager
      ->get_current_page() + $pager
      ->set_offset();
  }

  // Add the counter for the current site.
  $count += $this->view->row_index + 1;
  return $count;
}