You are here

public function FotoramaGalleryFormatter::viewElements in Fotorama Gallery 8

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

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 ImageFormatter::viewElements

File

src/Plugin/Field/FieldFormatter/FotoramaGalleryFormatter.php, line 192

Class

FotoramaGalleryFormatter
Plugin implementation of the 'fotorama_gallery display' formatter.

Namespace

Drupal\fotorama_gallery\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = parent::viewElements($items, $langcode);
  $elements['#theme'] = 'fotorama_gallery_field';

  // Common fields.
  $elements['attributes'] = $this
    ->viewElementsSelectsFields() + $this
    ->viewElementsNumberFields() + $this
    ->viewElementsCheckBoxFields();

  // Specials fields.
  if (!empty($this
    ->getSetting('dimensions')['ratio'])) {
    $elements['attributes']['data-ratio'] = $this
      ->getSetting('dimensions')['ratio'];
  }
  return $elements;
}