You are here

public function MediaController::updateData in Gutenberg 8.2

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

Updates file data.

Parameters

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

string|int $fid: File id.

Return value

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

Throws

\Symfony\Component\HttpKernel\Exception\HttpException

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

File

src/Controller/MediaController.php, line 258

Class

MediaController
Returns responses for our image routes.

Namespace

Drupal\gutenberg\Controller

Code

public function updateData(Request $request, $fid) {
  $data = json_decode($request
    ->getContent(), TRUE);
  if (json_last_error() !== JSON_ERROR_NONE) {
    throw new BadRequestHttpException('Request data could not be parsed.');
  }
  try {
    $this->mediaService
      ->updateMediaData($fid, $data);
  } catch (\Throwable $exception) {
    return new JsonResponse([
      'message' => 'Data could not be updated',
    ], JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
  }
  return new JsonResponse([
    'status' => 'ok',
  ]);
}