You are here

protected function ParagraphsTableFormatter::getEntities in Paragraphs table 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.

File

src/Plugin/Field/FieldFormatter/ParagraphsTableFormatter.php, line 531

Class

ParagraphsTableFormatter
Plugin implementation of the 'paragraphs_table_formatter' formatter.

Namespace

Drupal\paragraphs_table\Plugin\Field\FieldFormatter

Code

protected function getEntities(FieldItemListInterface $items) {
  $entity_type = $this->fieldDefinition
    ->getFieldStorageDefinition()
    ->getSetting('target_type');
  $entity_storage = \Drupal::entityTypeManager()
    ->getStorage($entity_type);
  $entities = [];
  foreach ($items as $item) {
    $entity_id = $item
      ->getValue()['target_id'];
    if ($entity_id) {
      $entity = $entity_storage
        ->load($entity_id);
      if ($entity && $entity
        ->access('view')) {
        $entities[] = $entity;
      }
    }
  }
  return $entities;
}