You are here

public function SlickFileFormatterBase::viewElements in Slick Carousel 8

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

File

src/Plugin/Field/FieldFormatter/SlickFileFormatterBase.php, line 57

Class

SlickFileFormatterBase
Base class for slick image and file ER formatters.

Namespace

Drupal\slick\Plugin\Field\FieldFormatter

Code

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

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

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

  // Build the elements.
  $this
    ->buildElements($build, $files);

  // Supports Blazy multi-breakpoint images if provided.
  $this->formatter
    ->isBlazy($build['settings'], $build['items'][0]);
  return $this
    ->manager()
    ->build($build);
}