public function VideoJsPlayerFormatter::viewElements in Video.js (HTML5 Video Player) 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 FormatterInterface::viewElements
1 method overrides VideoJsPlayerFormatter::viewElements()
- VideoJsPlayerListFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ VideoJsPlayerListFormatter.php - Builds a renderable array for a field value.
File
- src/
Plugin/ Field/ FieldFormatter/ VideoJsPlayerFormatter.php, line 166 - Contains \Drupal\videojs\Plugin\Field\FieldFormatter\VideJsPlayerFormatter.
Class
- VideoJsPlayerFormatter
- Plugin implementation of the 'videojs_player' formatter.
Namespace
Drupal\videojs\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
$files = $this
->getEntitiesToView($items, $langcode);
// Early opt-out if the field is empty.
if (empty($files)) {
return $elements;
}
// Collect cache tags to be added for each item in the field.
foreach ($files as $delta => $file) {
$video_uri = $file
->getFileUri();
$elements[$delta] = array(
'#theme' => 'videojs',
'#items' => array(
Url::fromUri(file_create_url($video_uri)),
),
'#player_attributes' => $this
->getSettings(),
'#attached' => array(
'library' => array(
'videojs/videojs',
),
),
);
}
return $elements;
}