public function VideoPlayerListFormatter::viewElements in Video 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/VideoPlayerListFormatter.php \Drupal\video\Plugin\Field\FieldFormatter\VideoPlayerListFormatter::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 VideoPlayerFormatter::viewElements
File
- src/
Plugin/ Field/ FieldFormatter/ VideoPlayerListFormatter.php, line 33
Class
- VideoPlayerListFormatter
- Plugin implementation of the 'video_player_list' 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.
$video_items = [];
foreach ($files as $delta => $file) {
$video_uri = $file
->getFileUri();
$relative_url = file_url_transform_relative(file_create_url($video_uri));
$video_items[] = Url::fromUserInput($relative_url);
}
$elements[] = [
'#theme' => 'video_player_formatter',
'#items' => $video_items,
'#player_attributes' => $this
->getSettings(),
];
return $elements;
}