You are here

public function MediaElementVideoFieldFormatter::viewElements in MediaElement 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 FileMediaFormatterBase::viewElements

File

src/Plugin/Field/FieldFormatter/MediaElementVideoFieldFormatter.php, line 255

Class

MediaElementVideoFieldFormatter
Plugin implementation of the 'mediaelement_file_video' formatter.

Namespace

Drupal\mediaelement\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = $this
    ->traitViewElements($items, $langcode);
  $poster_path = $this
    ->getPosterPath($items
    ->getEntity());
  if (!empty($poster_path)) {
    foreach ($elements as &$element) {
      $element['#attributes']
        ->setAttribute('poster', $poster_path);
    }
  }
  return $elements;
}