You are here

public function MediaController::load in Gutenberg 8

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

Get data of the media entity required for Gutenberg editor.

Parameters

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

\Drupal\file\Entity\File|null $file: Loaded found file entity instance.

Return value

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

Throws

\Exception

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

File

src/Controller/MediaController.php, line 185

Class

MediaController
Returns responses for our image routes.

Namespace

Drupal\gutenberg\Controller

Code

public function load(Request $request, ?File $file) {
  if (!$file) {
    return new JsonResponse([
      'error' => $this
        ->t('File entity not found.'),
    ], 404);
  }
  try {
    return new JsonResponse($this->mediaService
      ->loadFileData($file));
  } catch (FileEntityNotFoundException $exception) {
    return new JsonResponse($this
      ->t($exception
      ->getMessage()), 404);
  }
}