You are here

public function GridStackFormatterViewTrait::commonViewElements in GridStack 8.2

Returns similar view elements.

3 calls to GridStackFormatterViewTrait::commonViewElements()
GridStackEntityFormatterBase::viewElements in src/Plugin/Field/FieldFormatter/GridStackEntityFormatterBase.php
GridStackFileFormatterBase::viewElements in src/Plugin/Field/FieldFormatter/GridStackFileFormatterBase.php
GridStackMediaFormatter::viewElements in src/Plugin/Field/FieldFormatter/GridStackMediaFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/GridStackFormatterViewTrait.php, line 15

Class

GridStackFormatterViewTrait
A Trait common for all blazy formatters.

Namespace

Drupal\gridstack\Plugin\Field\FieldFormatter

Code

public function commonViewElements(FieldItemListInterface $items, $langcode, array $entities = [], array $settings = []) {

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

  // Build the settings.
  $build = [
    'settings' => $settings,
  ];

  // Modifies settings before building elements.
  $entities = empty($entities) ? [] : array_values($entities);
  $this->formatter
    ->preBuildElements($build, $items, $entities);

  // Build the elements.
  $elements = $entities ?: $items;
  $this
    ->buildElements($build, $elements, $langcode);

  // Modifies settings post building elements.
  $this->formatter
    ->postBuildElements($build, $items, $entities);

  // Pass to manager for easy updates to all Blazy formatters.
  return $this->manager
    ->build($build);
}