You are here

protected function AutoImageStyleMediaDefault::getEntitiesToView in Auto image style 8

Returns the referenced entities for display.

The method takes care of:

  • checking entity access,
  • placing the entities in the language expected for display.

It is thus strongly recommended that formatters use it in their implementation of viewElements($items) rather than dealing with $items directly.

For each entity, the EntityReferenceItem by which the entity is referenced is available in $entity->_referringItem. This is useful for field types that store additional values next to the reference itself.

Parameters

\Drupal\Core\Field\EntityReferenceFieldItemListInterface $items: The item list.

string $langcode: The language code of the referenced entities to display.

Return value

\Drupal\Core\Entity\EntityInterface[] The array of referenced entities to display, keyed by delta.

Overrides ImageFormatterBase::getEntitiesToView

See also

::prepareView()

1 call to AutoImageStyleMediaDefault::getEntitiesToView()
AutoImageStyleMediaDefault::viewElements in src/Plugin/Field/FieldFormatter/AutoImageStyleMediaDefault.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/AutoImageStyleMediaDefault.php, line 131

Class

AutoImageStyleMediaDefault
Plugin for responsive media image formatter.

Namespace

Drupal\auto_image_style\Plugin\Field\FieldFormatter

Code

protected function getEntitiesToView(EntityReferenceFieldItemListInterface $items, $langcode) {
  $media = parent::getEntitiesToView($items, $langcode);
  $entities = [];
  foreach ($media as $media_item) {
    $entity = $media_item->thumbnail->entity;
    $entity->_referringItem = $media_item->thumbnail;
    $entities[] = $entity;
  }
  return $entities;
}