public function Counter::getValue

Get the value that's supposed to be rendered.

This api exists so that other modules can easy set the values of the field without having the need to change the render method as well.

Parameters

$values: An object containing all retrieved values.

$field: Optional name of the field where the value is stored.

Overrides FieldPluginBase::getValue

File

drupal/core/modules/views/lib/Drupal/views/Plugin/views/field/Counter.php, line 46
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 getValue($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
    ->usePager()) {
    $count += $pager
      ->getItemsPerPage() * $pager
      ->getCurrentPage() + $pager
      ->setOffset();
  }

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