You are here

protected function FormatterBase::getEntitiesToView in Reference Table Formatter 8

Get the entities which will make up the table.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field items.

Return value

array An array of loaded entities.

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

File

src/FormatterBase.php, line 63

Class

FormatterBase
A base field formatter class for rendering tables.

Namespace

Drupal\reference_table_formatter

Code

protected function getEntitiesToView(FieldItemListInterface $items) {
  $entity_type = $this
    ->getTargetEntityId($this->fieldDefinition);
  $entity_storage = $this->entityManager
    ->getStorage($entity_type);
  $entities = [];
  foreach ($items as $item) {
    $entity_id = $this
      ->getEntityIdFromFieldItem($item);
    if ($entity_id) {
      $entity = $entity_storage
        ->load($entity_id);
      if ($entity && $entity
        ->access('view')) {
        $entities[] = $entity;
      }
    }
  }
  return $entities;
}