You are here

public function GridStackEntityFormatterBase::viewElements in GridStack 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/GridStackEntityFormatterBase.php \Drupal\gridstack\Plugin\Field\FieldFormatter\GridStackEntityFormatterBase::viewElements()

File

src/Plugin/Field/FieldFormatter/GridStackEntityFormatterBase.php, line 77

Class

GridStackEntityFormatterBase
Base class for gridstack entity reference formatters without field details.

Namespace

Drupal\gridstack\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $entities = $this
    ->getEntitiesToView($items, $langcode);

  // Early opt-out if the field is empty.
  if (empty($entities)) {
    return [];
  }

  // Collects specific settings to this formatter.
  $settings = $this
    ->buildSettings();
  $build = [
    'settings' => $settings,
  ];
  $this->formatter
    ->buildSettings($build, $items);

  // Build the elements.
  $this
    ->buildElements($build, $entities, $langcode);
  return $this
    ->manager()
    ->build($build);
}