Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. EntityField.php

function EntityField::prepareItemsByDelta

Adapts the $items according to the delta configuration.

This selects displayed deltas, reorders items, and takes offsets into account.

Parameters

array $all_values: The items for individual rendering.

Return value

array The manipulated items.

1 call to EntityField::prepareItemsByDelta()
EntityField::getItems in core/modules/views/src/Plugin/views/field/EntityField.php
Gets an array of items for the field.

File

core/modules/views/src/Plugin/views/field/EntityField.php, line 766

Class

EntityField
A field that displays entity field data.

Namespace

Drupal\views\Plugin\views\field

Code

protected function prepareItemsByDelta(array $all_values) {
    if ($this->options['delta_reversed']) {
        $all_values = array_reverse($all_values);
    }
    // We are supposed to show only certain deltas.
    if ($this->limit_values) {
        $row = $this->view->result[$this->view->row_index];
        // Offset is calculated differently when row grouping for a field is not
        // enabled. Since there are multiple rows, delta needs to be taken into
        // account, so that different values are shown per row.
        if (!$this->options['group_rows'] && isset($this->aliases['delta']) && isset($row->{$this->aliases['delta']})) {
            $delta_limit = 1;
            $offset = $row->{$this->aliases['delta']};
        }
        elseif (!$this->options['group_rows'] && !$this->multiple) {
            $delta_limit = 1;
            $offset = 0;
        }
        else {
            $delta_limit = (int) $this->options['delta_limit'];
            $offset = intval($this->options['delta_offset']);
            // We should only get here in this case if there is an offset, and in
            // that case we are limiting to all values after the offset.
            if ($delta_limit === 0) {
                $delta_limit = count($all_values) - $offset;
            }
        }
        // Determine if only the first and last values should be shown.
        $delta_first_last = $this->options['delta_first_last'];
        $new_values = [];
        for ($i = 0; $i < $delta_limit; $i++) {
            $new_delta = $offset + $i;
            if (isset($all_values[$new_delta])) {
                // If first-last option was selected, only use the first and last
                // values.
                if (!$delta_first_last || $new_delta == $offset || $new_delta == $delta_limit + $offset - 1) {
                    $new_values[] = $all_values[$new_delta];
                }
            }
        }
        $all_values = $new_values;
    }
    return $all_values;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal