function EntityField::getItems

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/field/EntityField.php \Drupal\views\Plugin\views\field\EntityField::getItems()
  2. 8.9.x core/modules/views/src/Plugin/views/field/EntityField.php \Drupal\views\Plugin\views\field\EntityField::getItems()
  3. 10 core/modules/views/src/Plugin/views/field/EntityField.php \Drupal\views\Plugin\views\field\EntityField::getItems()

Gets an array of items for the field.

Parameters

\Drupal\views\ResultRow $values: The result row object containing the values.

Return value

array An array of items for the field.

Overrides MultiItemsFieldHandlerInterface::getItems

3 calls to EntityField::getItems()
CommentedEntity::getItems in core/modules/comment/src/Plugin/views/field/CommentedEntity.php
Gets an array of items for the field.
Depth::getItems in core/modules/comment/src/Plugin/views/field/Depth.php
Gets an array of items for the field.
TermName::getItems in core/modules/taxonomy/src/Plugin/views/field/TermName.php
Gets an array of items for the field.
3 methods override EntityField::getItems()
CommentedEntity::getItems in core/modules/comment/src/Plugin/views/field/CommentedEntity.php
Gets an array of items for the field.
Depth::getItems in core/modules/comment/src/Plugin/views/field/Depth.php
Gets an array of items for the field.
TermName::getItems in core/modules/taxonomy/src/Plugin/views/field/TermName.php
Gets an array of items for the field.

File

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

Class

EntityField
A field that displays entity field data.

Namespace

Drupal\views\Plugin\views\field

Code

public function getItems(ResultRow $values) {
    if (!$this->displayHandler
        ->useGroupBy()) {
        $build_list = $this->getEntityFieldRenderer()
            ->render($values, $this);
    }
    else {
        // For grouped results we need to retrieve a massaged entity having
        // grouped field values to ensure that "grouped by" values, especially
        // those with multiple cardinality work properly. See
        // \Drupal\Tests\views\Kernel\QueryGroupByTest::testGroupByFieldWithCardinality.
        $display = [
            'type' => $this->options['type'],
            'settings' => $this->options['settings'],
            'label' => 'hidden',
        ];
        // Optional relationships may not provide an entity at all. So we can't
        // use createEntityForGroupBy() for those rows.
        if ($entity = $this->getEntity($values)) {
            $entity = $this->createEntityForGroupBy($entity, $values);
            // Some bundles might not have a specific field, in which case the faked
            // entity doesn't have it either.
            $build_list = isset($entity->{$this->definition['field_name']}) ? $entity->{$this->definition['field_name']}
                ->view($display) : NULL;
        }
        else {
            $build_list = NULL;
        }
    }
    if (!$build_list) {
        return [];
    }
    if ($this->options['field_api_classes']) {
        return [
            [
                'rendered' => $build_list,
            ],
        ];
    }
    // Render using the formatted data itself.
    $items = [];
    // Each item is extracted and rendered separately, the top-level formatter
    // render array itself is never rendered, so we extract its bubbleable
    // metadata and add it to each child individually.
    $bubbleable = BubbleableMetadata::createFromRenderArray($build_list);
    foreach (Element::children($build_list) as $delta) {
        BubbleableMetadata::createFromRenderArray($build_list[$delta])->merge($bubbleable)
            ->applyTo($build_list[$delta]);
        $items[$delta] = [
            'rendered' => $build_list[$delta],
            // Add the raw field items (for use in tokens).
'raw' => $build_list['#items'][$delta],
        ];
    }
    return $this->prepareItemsByDelta($items);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.