You are here

class FillPdfDownloadAction in FillPDF 8.4

Same name and namespace in other branches
  1. 5.0.x src/Plugin/FillPdfActionPlugin/FillPdfDownloadAction.php \Drupal\fillpdf\Plugin\FillPdfActionPlugin\FillPdfDownloadAction

Action plugin sending a generated PDF file to the users browser.

@package Drupal\fillpdf\Plugin\FillPdfActionPlugin

Plugin annotation


@FillPdfActionPlugin(
  id = "download",
  label = @Translation("Download PDF")
)

Hierarchy

Expanded class hierarchy of FillPdfDownloadAction

File

src/Plugin/FillPdfActionPlugin/FillPdfDownloadAction.php, line 19

Namespace

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

  /**
   * Executes this plugin.
   *
   * Sends the PDF file to the user's browser.
   *
   * @return \Symfony\Component\HttpFoundation\Response
   *   Sends the PDF file to the browser.
   */
  public function execute() {
    $response = new Response($this->configuration['data']);

    // This ensures that the browser serves the file as a download.
    $disposition = $response->headers
      ->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $this->configuration['filename']);
    $response->headers
      ->set('Content-Disposition', $disposition);
    $response->headers
      ->set('Content-Type', 'application/pdf');
    $response->headers
      ->set('Content-Length', strlen($this->configuration['data']));
    return $response;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FillPdfActionPluginBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
FillPdfActionPluginBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 1
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.
FillPdfDownloadAction::execute public function Executes this plugin. Overrides FillPdfActionPluginInterface::execute
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 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92