/** * Returns the entity rendered via the given printable format. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to be printed. * @param string $printable_format * The identifier of the hadcopy format plugin. * * @return \Symfony\Component\HttpFoundation\Response * The printable response. */ 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); if ($printable_format == 'print') { return $format->getResponse(); } else { $format->getResponse($content); $source_url = \Drupal::request()->getRequestUri(); $pos = strpos($source_url, "printable"); $pos_node = strpos($source_url, '/', $pos + 11); $source_url = substr($source_url, 0, $pos) . substr($source_url, $pos_node + 1); return new RedirectResponse($source_url); } } else { throw new NotFoundHttpException(); } }