public function MediaElementFieldFormatterTrait::viewElements in MediaElement 8
1 call to MediaElementFieldFormatterTrait::viewElements()
- MediaElementVideoFieldFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ MediaElementVideoFieldFormatter.php - Builds a renderable array for a field value.
File
- src/
Plugin/ Field/ FieldFormatter/ MediaElementFieldFormatterTrait.php, line 86
Class
- MediaElementFieldFormatterTrait
- Common methods for MediaElement.js processing.
Namespace
Drupal\mediaelement\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = parent::viewElements($items, $langcode);
$library_source = \Drupal::config('mediaelement.settings')
->get('library_settings.library_source');
// Attach the MediaElement library to the elements as well as settings.
foreach ($elements as &$element) {
$element['#attributes']
->setAttribute('preload', $this->settings['preload']);
$element['#download_link'] = $this->settings['download_link'];
$element['#download_text'] = $this->settings['download_text'];
$element['#attached']['library'][] = "mediaelement/mediaelement_{$library_source}";
}
return $elements;
}