public function MediaService::renderDialog in Gutenberg 8.2
Same name and namespace in other branches
- 8 src/Service/MediaService.php \Drupal\gutenberg\Service\MediaService::renderDialog()
Renders media library dialog for Gutenberg editor.
Parameters
array $media_types: Array of media types.
Return value
string The rendered element.
Throws
\Drupal\gutenberg\Service\MediaTypeNotFoundException
File
- src/
Service/ MediaService.php, line 179
Class
- MediaService
- The media service class.
Namespace
Drupal\gutenberg\ServiceCode
public function renderDialog(array $media_types) {
$media_types = array_filter($media_types) ? $media_types : [
'application',
'image',
'audio',
'video',
'text',
];
$allowed_media_type_ids = [];
foreach ($media_types as $media_type) {
$allowed_media_type_ids = array_merge($allowed_media_type_ids, $this->mediaTypeGuesser
->guess($media_type));
}
if (!$allowed_media_type_ids) {
throw new MediaTypeNotFoundException();
}
$buildUi = $this->builder
->buildUi(MediaLibraryState::create('gutenberg.media_library.opener', array_unique($allowed_media_type_ids), reset($allowed_media_type_ids), 1));
$this->moduleHandler
->alter('gutenberg_media_library_view', $buildUi);
return $this->renderer
->render($buildUi);
}