You are here

public function PictureBackgroundFormatter::viewElements in Picture Background Formatter 8

Builds a renderable array for a field value.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.

string $langcode: The language that should be used to render the field.

Return value

array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.

Overrides ResponsiveImageFormatter::viewElements

1 method overrides PictureBackgroundFormatter::viewElements()
PictureBackgroundFormatterMedia::viewElements in src/Plugin/Field/FieldFormatter/PictureBackgroundFormatterMedia.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/PictureBackgroundFormatter.php, line 87

Class

PictureBackgroundFormatter
Plugin implementation of the 'picture_background_formatter' formatter.

Namespace

Drupal\picture_background_formatter\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = [];
  $entity = $items
    ->getEntity();

  // Load the files to render.
  $files = $this
    ->getEntitiesToView($items, $langcode);

  // Early opt-out if the field is empty.
  if (empty($files)) {
    return $elements;
  }
  return $this
    ->build_element($files, $entity);
}