src/Controller/EmatoSentEmailAdminController.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Sonata\AdminBundle\Controller\CRUDController;
  5. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use App\Entity\EmatoSentEmail;
  8. final class EmatoSentEmailAdminController extends CRUDController
  9. {
  10.     protected $pdfOutputDir;
  11.     public function __construct(string $pdfOutputDir)
  12.     {
  13.         $this->pdfOutputDir $pdfOutputDir;
  14.     }
  15.     public function pdfAction(Request $request)
  16.     {
  17.         /** @var EmatoSentEmail $sentEmail */
  18.         $sentEmail $this->admin->getSubject();
  19.         $pdfContent file_get_contents($this->pdfOutputDir '/emato/' $sentEmail->getPdf());
  20.         $response = new Response($pdfContent);
  21.         $disposition $response->headers->makeDisposition(
  22.             ResponseHeaderBag::DISPOSITION_INLINE,
  23.             $sentEmail->getPdf()
  24.         );
  25.         $response->headers->set('Content-Type''application/pdf');
  26.         $response->headers->set('Content-Disposition'$disposition);
  27.         return $response;
  28.     }
  29. }