You are here

public function PrintableController::showFormat in Printer and PDF versions for Drupal 8+ 8

Same name and namespace in other branches
  1. 2.x src/Controller/PrintableController.php \Drupal\printable\Controller\PrintableController::showFormat()

Returns the entity rendered via the given printable format.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to be printed.

string $printable_format: The identifier of the hadcopy format plugin.

Return value

\Symfony\Component\HttpFoundation\Response The printable response.

File

src/Controller/PrintableController.php, line 66

Class

PrintableController
Controller to display an entity in a particular printable format.

Namespace

Drupal\printable\Controller

Code

public function showFormat(EntityInterface $entity, $printable_format) {
  if ($this->printableFormatManager
    ->getDefinition($printable_format)) {
    $format = $this->printableFormatManager
      ->createInstance($printable_format);
    $content = $this
      ->entityManager()
      ->getViewBuilder($entity
      ->getEntityTypeId())
      ->view($entity, 'printable');
    $format
      ->setContent($content);
    return $format
      ->getResponse();
  }
  else {
    throw new NotFoundHttpException();
  }
}