diff --git a/src/Controller/HandlePdfController.php b/src/Controller/HandlePdfController.php index 406aead81ff4b59cf356add7864e73f916bf617a..7a41c6d892aa072346f810d9ab4ee0ac1317e745 100644 --- a/src/Controller/HandlePdfController.php +++ b/src/Controller/HandlePdfController.php @@ -193,7 +193,6 @@ class HandlePdfController extends ControllerBase { $output_name = $this->buildFilename($fillpdf_form->title->value, $token_objects); // Determine the appropriate action for the PDF. - // @todo: If they checked destination_redirect, make it redirect $destination_path_set = !empty($fillpdf_form->destination_path->value); $redirect = !empty($fillpdf_form->destination_redirect->value); if ($destination_path_set && !$redirect) { diff --git a/src/OutputHandlerInterface.php b/src/OutputHandlerInterface.php index 86cf837a0cd6d481f6fb50f57b831aab8b479460..6c2799aaada4142bdbc7318982fb8a593ae940e2 100644 --- a/src/OutputHandlerInterface.php +++ b/src/OutputHandlerInterface.php @@ -6,7 +6,7 @@ */ namespace Drupal\fillpdf; -use Drupal\file\Entity\File; +use Drupal\file\FileInterface; /** * Contains functions to standardize output handling for generated PDFs. @@ -27,7 +27,7 @@ interface OutputHandlerInterface { * the PDF should be presented. * * @param string $destination_path_override - * @return bool|\Drupal\file\Entity\File + * @return bool|FileInterface */ public function savePdfToFile(array $context, $destination_path_override = NULL); diff --git a/src/Plugin/FillPdfActionPlugin/FillPdfRedirectAction.php b/src/Plugin/FillPdfActionPlugin/FillPdfRedirectAction.php new file mode 100644 index 0000000000000000000000000000000000000000..8db29376dbeabdad128fbf579effd053d1454868 --- /dev/null +++ b/src/Plugin/FillPdfActionPlugin/FillPdfRedirectAction.php @@ -0,0 +1,36 @@ +<?php +/** + * @file + * Contains \Drupal\fillpdf\Plugin\FillPdfActionPlugin\FillPdfRedirectAction. + */ + +namespace Drupal\fillpdf\Plugin\FillPdfActionPlugin; + +use Drupal\Core\Annotation\Translation; +use Drupal\fillpdf\Annotation\FillPdfActionPlugin; +use Drupal\fillpdf\OutputHandler; +use Drupal\fillpdf\Plugin\FillPdfActionPluginBase; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; + +/** + * Class FillPdfRedirectAction + * @package Drupal\fillpdf\Plugin\FillPdfActionPlugin + * + * @FillPdfActionPlugin( + * id = "redirect", + * label = @Translation("Redirect PDF to file") + * ) + */ +class FillPdfRedirectAction extends FillPdfSaveAction { + + public function execute() { + $saved_file = $this->savePdf(); + + // Get file URI, then return a RedirectResponse to it. + $destination = $saved_file->url(); + + return new RedirectResponse($destination); + } + +} diff --git a/src/Plugin/FillPdfActionPlugin/FillPdfSaveAction.php b/src/Plugin/FillPdfActionPlugin/FillPdfSaveAction.php index 3c17893dd2914351f2f0946ddabed1b7c4ff65e8..ba8fd31c951b350c8f33bd993420c9be955d7a87 100644 --- a/src/Plugin/FillPdfActionPlugin/FillPdfSaveAction.php +++ b/src/Plugin/FillPdfActionPlugin/FillPdfSaveAction.php @@ -38,12 +38,16 @@ class FillPdfSaveAction extends FillPdfActionPluginBase { } public function execute() { - // @todo: Error handling? - $this->outputHandler->savePdfToFile($this->configuration); + $this->savePdf(); // @todo: Fix based on value of post_save_redirect, once I add that $response = new RedirectResponse('/'); return $response; } + protected function savePdf() { + // @todo: Error handling? + return $this->outputHandler->savePdfToFile($this->configuration); + } + }