public function SoundcloudEmbedFormatter::viewElements in Media entity Soundcloud 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/SoundcloudEmbedFormatter.php \Drupal\media_entity_soundcloud\Plugin\Field\FieldFormatter\SoundcloudEmbedFormatter::viewElements()
- 3.x src/Plugin/Field/FieldFormatter/SoundcloudEmbedFormatter.php \Drupal\media_entity_soundcloud\Plugin\Field\FieldFormatter\SoundcloudEmbedFormatter::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
File
- src/
Plugin/ Field/ FieldFormatter/ SoundcloudEmbedFormatter.php, line 110
Class
- SoundcloudEmbedFormatter
- Plugin implementation of the 'soundcloud_embed' formatter.
Namespace
Drupal\media_entity_soundcloud\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
/** @var \Drupal\media_entity\MediaInterface $media_entity */
$media_entity = $items
->getEntity();
$element = [];
if (($type = $media_entity
->getType()) && $type instanceof Soundcloud) {
/** @var MediaTypeInterface $item */
foreach ($items as $delta => $item) {
if ($track_id = $type
->getField($media_entity, 'track_id')) {
$element[$delta] = [
'#theme' => 'media_soundcloud_embed',
'#track_id' => $track_id,
'#width' => $this
->getSetting('width'),
'#height' => $this
->getSetting('height'),
'#type' => $this
->getSetting('type'),
'#options' => $this
->getSetting('options'),
];
}
}
}
return $element;
}