public function MediaService::getRenderedMediaEntity in Gutenberg 8
Same name and namespace in other branches
- 8.2 src/Service/MediaService.php \Drupal\gutenberg\Service\MediaService::getRenderedMediaEntity()
Render media entities.
Parameters
\Drupal\media\MediaInterface $media_entity: Media entity instance.
Return value
array The rendered view modes.
File
- src/
Service/ MediaService.php, line 209
Class
- MediaService
- The media service class.
Namespace
Drupal\gutenberg\ServiceCode
public function getRenderedMediaEntity(MediaInterface $media_entity) {
$rendered_view_modes = [];
try {
/** @var \Drupal\media\Entity\Media $media_entity */
$view_modes = $this->entityDisplayRepository
->getViewModeOptionsByBundle('media', $media_entity
->bundle());
foreach ($view_modes as $view_mode => $view_mode_name) {
$rendered_view_modes[$view_mode] = [
'view_mode' => $view_mode,
'view_mode_name' => (string) $view_mode_name,
'html' => $this->mediaEntityRenderer
->render($media_entity, $view_mode),
];
}
} catch (\Throwable $exception) {
// Catch silently.
}
return $rendered_view_modes;
}