You are here

public function SlickEntityFormatterBase::viewElements in Slick Carousel 8

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

File

src/Plugin/Field/FieldFormatter/SlickEntityFormatterBase.php, line 79

Class

SlickEntityFormatterBase
Base class for slick entity reference formatters without field details.

Namespace

Drupal\slick\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
    ->getSettings();

  // Asks for Blazy to deal with iFrames, and mobile-optimized lazy loading.
  $settings['blazy'] = TRUE;
  $settings['plugin_id'] = $this
    ->getPluginId();
  $settings['vanilla'] = TRUE;
  $build = [
    'settings' => $settings,
  ];
  $this->formatter
    ->buildSettings($build, $items);

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