You are here

public function TextimageDownloadController::deferredDelivery in Textimage 8.4

Same name and namespace in other branches
  1. 8.3 src/Controller/TextimageDownloadController.php \Drupal\textimage\Controller\TextimageDownloadController::deferredDelivery()

Deliver a Textimage from a deferred request.

After generating an image, transfer it to the requesting agent.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

Return value

\Symfony\Component\HttpFoundation\BinaryFileResponse|\Symfony\Component\HttpFoundation\Response The transferred file as response or some error response.

Throws

\Symfony\Component\HttpKernel\Exception\NotFoundHttpException Thrown when the textimage ID is not found.

File

src/Controller/TextimageDownloadController.php, line 183

Class

TextimageDownloadController
Defines a controller to serve image styles.

Namespace

Drupal\textimage\Controller

Code

public function deferredDelivery(Request $request) {

  // Identify Textimage id.
  $file = $request->query
    ->get('file');
  $tiid = str_replace('.' . pathinfo($file, PATHINFO_EXTENSION), '', pathinfo($file, PATHINFO_BASENAME));

  // Get the Textimage URI.
  try {
    $image_uri = $this->textimageFactory
      ->load($tiid)
      ->buildImage()
      ->getUri();
    return $this
      ->returnBinary($request, $image_uri);
  } catch (TextimageException $e) {
    $this->logger
      ->error("Failed to build an image at '%file_uri'.", [
      '%file_uri' => $file,
    ]);
    throw new NotFoundHttpException('Image not found');
  }
}