You are here

public function MediaController::loadMedia in Gutenberg 8

Same name and namespace in other branches
  1. 8.2 src/Controller/MediaController.php \Drupal\gutenberg\Controller\MediaController::loadMedia()

Load media data.

Parameters

\Symfony\Component\HttpFoundation\Request $request: Current request.

string $media: Media data (numeric or stringified JSON for media data processing).

Return value

\Symfony\Component\HttpFoundation\JsonResponse The JSON response.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

1 string reference to 'MediaController::loadMedia'
gutenberg.routing.yml in ./gutenberg.routing.yml
gutenberg.routing.yml

File

src/Controller/MediaController.php, line 96

Class

MediaController
Returns responses for our image routes.

Namespace

Drupal\gutenberg\Controller

Code

public function loadMedia(Request $request, string $media) {
  $media_entities = $this->mediaSelectionProcessorManager
    ->processData($media);
  try {
    if (!$media_entities) {
      throw new MediaEntityNotFoundException();
    }
    return new JsonResponse($this->mediaService
      ->loadMediaData(reset($media_entities)));
  } catch (MediaEntityNotFoundException $exception) {
    return new JsonResponse($this
      ->t($exception
      ->getMessage()), 404);
  }
}