You are here

public function VideoPlayerHTML5::viewElements in Media entity video 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/Field/FieldFormatter/VideoPlayerHTML5.php \Drupal\media_entity_video\Plugin\Field\FieldFormatter\VideoPlayerHTML5::viewElements()
  2. 8.2 src/Plugin/Field/FieldFormatter/VideoPlayerHTML5.php \Drupal\media_entity_video\Plugin\Field\FieldFormatter\VideoPlayerHTML5::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 FormatterInterface::viewElements

File

src/Plugin/Field/FieldFormatter/VideoPlayerHTML5.php, line 77

Class

VideoPlayerHTML5
Plugin implementation of the 'Video Player (HTML5)' formatter.

Namespace

Drupal\media_entity_video\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = array();
  $provide_download_link = $this
    ->getSetting('provide_download_link');
  $video_attributes = $this
    ->getSetting('video_attributes');
  foreach ($this
    ->getEntitiesToView($items, $langcode) as $delta => $file) {
    $item = $file->_referringItem;
    $elements[$delta] = array(
      '#theme' => 'media_video_file_formatter',
      '#file' => $file,
      '#description' => $item->description,
      '#value' => $provide_download_link,
      '#extravalue' => $video_attributes,
      '#cache' => array(
        'tags' => $file
          ->getCacheTags(),
      ),
    );

    // Pass field item attributes to the theme function.
    if (isset($item->_attributes)) {
      $elements[$delta] += array(
        '#attributes' => array(),
      );
      $elements[$delta]['#attributes'] += $item->_attributes;

      // Unset field item attributes since they have been included in the
      // formatter output and should not be rendered in the field template.
      unset($item->_attributes);
    }
  }
  return $elements;
}