added inline disposition for PDF previews (#3486)

This commit is contained in:
Alexander Pankow
2022-09-04 12:15:47 +02:00
committed by GitHub
parent 1d1f5835da
commit 2fbbbe7260
9 changed files with 107 additions and 10 deletions

View File

@@ -10,16 +10,19 @@
namespace App\Invoice\Renderer;
use App\Entity\InvoiceDocument;
use App\Export\Base\DispositionInlineInterface;
use App\Export\Base\DispositionInlineTrait;
use App\Export\ExportContext;
use App\Invoice\InvoiceFilename;
use App\Invoice\InvoiceModel;
use App\Utils\HtmlToPdfConverter;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Twig\Environment;
final class PdfRenderer extends AbstractTwigRenderer
final class PdfRenderer extends AbstractTwigRenderer implements DispositionInlineInterface
{
use DispositionInlineTrait;
/**
* @var HtmlToPdfConverter
*/
@@ -58,7 +61,7 @@ final class PdfRenderer extends AbstractTwigRenderer
$response = new Response($content);
$disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename . '.pdf');
$disposition = $response->headers->makeDisposition($this->getDisposition(), $filename . '.pdf');
$response->headers->set('Content-Type', 'application/pdf');
$response->headers->set('Content-Disposition', $disposition);

View File

@@ -17,6 +17,7 @@ use App\Event\InvoiceCreatedEvent;
use App\Event\InvoiceDeleteEvent;
use App\Event\InvoicePostRenderEvent;
use App\Event\InvoicePreRenderEvent;
use App\Export\Base\DispositionInlineInterface;
use App\Repository\InvoiceDocumentRepository;
use App\Repository\InvoiceRepository;
use App\Repository\Query\InvoiceQuery;
@@ -309,7 +310,7 @@ final class ServiceInvoice
}
}
public function renderInvoiceWithModel(InvoiceModel $model, EventDispatcherInterface $dispatcher): Response
public function renderInvoiceWithModel(InvoiceModel $model, EventDispatcherInterface $dispatcher, bool $dispositionInline = false): Response
{
$document = $this->getDocumentByName($model->getTemplate()->getRenderer());
if (null === $document) {
@@ -320,6 +321,10 @@ final class ServiceInvoice
if ($renderer->supports($document)) {
$dispatcher->dispatch(new InvoicePreRenderEvent($model, $document, $renderer));
if ($renderer instanceof DispositionInlineInterface) {
$renderer->setDispositionInline($dispositionInline);
}
$response = $renderer->render($document, $model);
$dispatcher->dispatch(new InvoicePostRenderEvent($model, $document, $renderer, $response));