You are here

public function MediaController::updateData in Gutenberg 8

Same name and namespace in other branches
  1. 8.2 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

\Exception

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

File

src/Controller/MediaController.php, line 230

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 \Exception("Request data couldn't be parsed.");
  }
  try {
    $this->mediaService
      ->updateMediaData($fid, $data);
  } catch (\Throwable $exception) {
    return new JsonResponse([
      'error' => $this
        ->t("Data couldn't be updated"),
    ], 500);
  }
  return new JsonResponse([
    'status' => 'ok',
  ]);
}