public function VideoPlayerFormatter::viewElements in Video 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/VideoPlayerFormatter.php \Drupal\video\Plugin\Field\FieldFormatter\VideoPlayerFormatter::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
1 method overrides VideoPlayerFormatter::viewElements()
- VideoPlayerListFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ VideoPlayerListFormatter.php - Builds a renderable array for a field value.
File
- src/
Plugin/ Field/ FieldFormatter/ VideoPlayerFormatter.php, line 160
Class
- VideoPlayerFormatter
- Plugin implementation of the 'video_player' formatter.
Namespace
Drupal\video\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$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();
$relative_url = file_url_transform_relative(file_create_url($video_uri));
$elements[$delta] = [
'#theme' => 'video_player_formatter',
'#items' => [
Url::fromUserInput($relative_url),
],
'#player_attributes' => $this
->getSettings(),
];
}
return $elements;
}