function Counter::getValue
Same name in other branches
- 8.9.x core/modules/views/src/Plugin/views/field/Counter.php \Drupal\views\Plugin\views\field\Counter::getValue()
- 10 core/modules/views/src/Plugin/views/field/Counter.php \Drupal\views\Plugin\views\field\Counter::getValue()
- 11.x core/modules/views/src/Plugin/views/field/Counter.php \Drupal\views\Plugin\views\field\Counter::getValue()
Overrides UncacheableFieldHandlerTrait::getValue
File
-
core/
modules/ views/ src/ Plugin/ views/ field/ Counter.php, line 60
Class
- Counter
- Field handler to show a counter of the current row.
Namespace
Drupal\views\Plugin\views\fieldCode
public function getValue(ResultRow $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->getOffset();
}
// Add the counter for the current site.
$count += $this->view->row_index + 1;
return $count;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.