public function MediaController::render in Gutenberg 8.2
Same name and namespace in other branches
- 8 src/Controller/MediaController.php \Drupal\gutenberg\Controller\MediaController::render()
Render provided media entity.
Parameters
string $media: Media data (numeric or stringified JSON for media data processing).
Return value
\Symfony\Component\HttpFoundation\JsonResponse The JSON response.
1 string reference to 'MediaController::render'
File
- src/
Controller/ MediaController.php, line 141
Class
- MediaController
- Returns responses for our image routes.
Namespace
Drupal\gutenberg\ControllerCode
public function render(string $media) {
$media_entities = $this->mediaSelectionProcessorManager
->processData($media);
try {
if (!$media_entities) {
throw new MediaEntityNotFoundException();
}
$media_entity = reset($media_entities);
return new JsonResponse([
'view_modes' => $this->mediaService
->getRenderedMediaEntity($media_entity),
'media_entity' => [
'id' => $media_entity
->id(),
'type' => $media_entity
->bundle(),
],
]);
} catch (MediaEntityNotFoundException $exception) {
throw new NotFoundHttpException($exception
->getMessage(), $exception);
}
}