public function PdfFormat::__construct in Printer and PDF versions for Drupal 8+ 2.x
Same name and namespace in other branches
- 8 modules/printable_pdf/src/Plugin/PrintableFormat/PdfFormat.php \Drupal\printable_pdf\Plugin\PrintableFormat\PdfFormat::__construct()
Parameters
array $configuration: The configuration array.
string $plugin_id: The plugin id.
array $plugin_definition: The plugin definition.
\Drupal\Core\Config\ConfigFactory $config_factory: The config factory service.
\Drupal\pdf_api\PdfGeneratorPluginManager $pdf_generator_manager: The PDF generator plugin manager service.
\Drupal\printable\PrintableCssIncludeInterface $printable_css_include: The printable CSS include interface.
\Drupal\printable\LinkExtractor\LinkExtractorInterface $link_extractor: The Link extractor service.
\Drupal\Core\Path\CurrentPathStack $pathCurrent: Represents the current path for the current request.
\Symfony\Component\HttpFoundation\RequestStack $requestStack: Request stack that controls the lifecycle of requests.
\Drupal\Core\StreamWrapper\PublicStream $public_stream: The public stream wrapper service.
\Drupal\Core\Messenger\MessengerInterface $messenger: The Drupal messenger service.
Overrides PrintableFormatBase::__construct
File
- modules/
printable_pdf/ src/ Plugin/ PrintableFormat/ PdfFormat.php, line 110
Class
- PdfFormat
- Provides a plugin to display a PDF version of a page.
Namespace
Drupal\printable_pdf\Plugin\PrintableFormatCode
public function __construct(array $configuration, $plugin_id, array $plugin_definition, ConfigFactory $config_factory, PdfGeneratorPluginManager $pdf_generator_manager, PrintableCssIncludeInterface $printable_css_include, LinkExtractorInterface $link_extractor, CurrentPathStack $pathCurrent, RequestStack $requestStack, PublicStream $public_stream, MessengerInterface $messenger) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $config_factory, $printable_css_include, $link_extractor);
$this->pdfGeneratorManager = $pdf_generator_manager;
$this->pathCurrent = $pathCurrent;
$this->requestStack = $requestStack;
$this->publicStream = $public_stream;
$this->messenger = $messenger;
$pdf_library = (string) $this->configFactory
->get('printable.settings')
->get('pdf_tool');
if (!$pdf_library) {
$this->messenger
->addError($this
->t('A PDF generation toolkit needs to be selected. Please visit the %link.', [
'%link' => Link::fromTextAndUrl('admin interface', Url::fromRoute('printable.format_configure_pdf'))
->toString(),
]));
throw new NotFoundHttpException();
return;
}
$pdf_library = strtolower($pdf_library);
$this->pdfGenerator = $this->pdfGeneratorManager
->createInstance($pdf_library);
if ($pdf_library != 'wkhtmltopdf') {
return;
}
$options = [
'enable-local-file-access',
];
$use_xvfb_run = (string) $this->configFactory
->get('printable.settings')
->get('print_pdf_use_xvfb_run');
$path_to_xfb_run = (string) $this->configFactory
->get('printable.settings')
->get('path_to_xfb_run');
$ignore_warnings = (bool) $this->configFactory
->get('printable.settings')
->get('ignore_warnings');
if ($use_xvfb_run) {
$options = [
'use-xserver' => NULL,
'commandOptions' => [
'enableXvfb' => TRUE,
'xvfbRunBinary' => $path_to_xfb_run,
],
'ignoreWarnings' => $ignore_warnings,
'enable-local-file-access',
];
}
$this->pdfGenerator
->getObject()
->setOptions($options);
}