public function AudioStreamHTML5::viewElements in Media entity audio 8.3
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/ AudioStreamHTML5.php, line 64
Class
- AudioStreamHTML5
- Plugin implementation of the 'Audio Stream (HTML5)' formatter.
Namespace
Drupal\media_entity_audio\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#theme' => 'media_audio',
'#sources' => [
$item->uri,
],
'#controls' => $this
->getSetting('controls'),
];
// Pass field item attributes to the theme function.
if (isset($item->_attributes)) {
$elements[$delta] += [
'#attributes' => [],
];
$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;
}