You are here

class FillPdfSaveAction in FillPDF 5.0.x

Same name and namespace in other branches
  1. 8.4 src/Plugin/FillPdfActionPlugin/FillPdfSaveAction.php \Drupal\fillpdf\Plugin\FillPdfActionPlugin\FillPdfSaveAction

Action plugin saving a generated PDF file to the filesystem.

@package Drupal\fillpdf\Plugin\FillPdfActionPlugin

Plugin annotation


@FillPdfActionPlugin(
  id = "save",
  label = @Translation("Save PDF to file")
)

Hierarchy

Expanded class hierarchy of FillPdfSaveAction

File

src/Plugin/FillPdfActionPlugin/FillPdfSaveAction.php, line 21

Namespace

Drupal\fillpdf\Plugin\FillPdfActionPlugin
View source
class FillPdfSaveAction extends FillPdfActionPluginBase {

  /**
   * The FillPdf output handler.
   *
   * @var \Drupal\fillpdf\OutputHandler
   */
  protected $outputHandler;

  /**
   * Constructs a \Drupal\Component\Plugin\PluginBase object.
   *
   * @param \Drupal\fillpdf\OutputHandler $output_handler
   *   The FillPdf output handler.
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   */
  public function __construct(OutputHandler $output_handler, array $configuration, $plugin_id, $plugin_definition) {
    $this->outputHandler = $output_handler;
    parent::__construct($configuration, $plugin_id, $plugin_definition);
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($container
      ->get('fillpdf.output_handler'), $configuration, $plugin_id, $plugin_definition);
  }

  /**
   * Executes this plugin.
   *
   * Saves the PDF file to the filesystem and redirects to the front page.
   *
   * @return \Symfony\Component\HttpFoundation\RedirectResponse
   *   Redirects user to the front page.
   */
  public function execute() {
    $this
      ->savePdf();

    // @todo: Fix based on value of post_save_redirect, once I add that
    $response = new RedirectResponse(Url::fromRoute('<front>')
      ->toString());
    return $response;
  }

  /**
   * Saves merged PDF data to the filesystem.
   *
   * @return \Drupal\file\FileInterface|false
   *   The saved file entity, or FALSE on error.
   *
   * @see \Drupal\fillpdf\OutputHandlerInterface::savePdfToFile()
   */
  protected function savePdf() {

    // @todo: Error handling?
    return $this->outputHandler
      ->savePdfToFile($this->configuration);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FillPdfActionPluginBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
FillPdfActionPluginBase::defaultConfiguration Deprecated public function Gets default configuration for this plugin.
FillPdfActionPluginBase::getConfiguration Deprecated public function Gets this plugin's configuration.
FillPdfActionPluginBase::isConfigurable public function @todo Remove once drupal:8.6.x is no longer supported. Overrides PluginBase::isConfigurable
FillPdfActionPluginBase::setConfiguration Deprecated public function Sets the configuration for this plugin instance.
FillPdfSaveAction::$outputHandler protected property The FillPdf output handler.
FillPdfSaveAction::create public static function Creates an instance of the plugin. Overrides FillPdfActionPluginBase::create
FillPdfSaveAction::execute public function Executes this plugin. Overrides FillPdfActionPluginInterface::execute 1
FillPdfSaveAction::savePdf protected function Saves merged PDF data to the filesystem.
FillPdfSaveAction::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId