You are here

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

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

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, FALSE)) {
    throw new NotFoundHttpException();
  }
  $format = $this->printableFormatManager
    ->createInstance($printable_format);
  $content = $this
    ->entityTypeManager()
    ->getViewBuilder($entity
    ->getEntityTypeId())
    ->view($entity, 'printable');
  $format
    ->setContent($content);
  return $format
    ->getResponse();
}