diff --git a/src/Controller/EntityPrintController.php b/src/Controller/EntityPrintController.php index 128ca92..28d7eaa 100644 --- a/src/Controller/EntityPrintController.php +++ b/src/Controller/EntityPrintController.php @@ -80,7 +80,7 @@ class EntityPrintController extends ControllerBase { $entity = $this->entityTypeManager->getStorage($entity_type)->load($entity_id); try { - $print_engine = $this->pluginManager->createInstance($config->get('print_engines')); + $print_engine = $this->pluginManager->createInstance($config->get('print_engines.pdf_engine')); } catch (PrintEngineException $e) { // Build a safe markup string using Xss::filter() so that the instructions diff --git a/src/Form/SettingsForm.php b/src/Form/SettingsForm.php index ed8489e..47930ff 100644 --- a/src/Form/SettingsForm.php +++ b/src/Form/SettingsForm.php @@ -123,10 +123,10 @@ class SettingsForm extends ConfigFormBase { $form['entity_print']['print_engine'] = [ '#type' => 'select', - '#title' => $this->t('Print Engine'), - '#description' => $this->t('Select the Print engine to render the Print'), + '#title' => $this->t('PDF Engine'), + '#description' => $this->t('Select the PDF engine to render the Print'), '#options' => $print_engines, - '#default_value' => $config->get('print_engine'), + '#default_value' => $config->get('print_engines.pdf_engine'), '#empty_option' => $this->t('- None -'), '#ajax' => [ 'callback' => '::ajaxPluginFormCallback', @@ -142,7 +142,7 @@ class SettingsForm extends ConfigFormBase { // If we have a print_engine in the form_state then use that otherwise, fall // back to what was saved as this is a fresh form. Check explicitly for NULL // in case they selected the None option which is false'y. - $plugin_id = !is_null($form_state->getValue('print_engine')) ? $form_state->getValue('print_engine') : $config->get('print_engine'); + $plugin_id = !is_null($form_state->getValue('print_engine')) ? $form_state->getValue('print_engine') : $config->get('print_engines.pdf_engine'); // If we have a plugin id and the plugin hasn't since been disabled then we // load the config for the plugin. @@ -215,7 +215,7 @@ class SettingsForm extends ConfigFormBase { $this->config('entity_print.settings') ->set('default_css', $values['default_css']) ->set('force_download', $values['force_download']) - ->set('print_engine', $values['print_engine']) + ->set('print_engines.pdf_engine', $values['print_engine']) ->save(); } diff --git a/src/Plugin/Action/PdfDownload.php b/src/Plugin/Action/PdfDownload.php index 0a58cd3..bbecb05 100644 --- a/src/Plugin/Action/PdfDownload.php +++ b/src/Plugin/Action/PdfDownload.php @@ -148,7 +148,7 @@ class PdfDownload extends ActionBase implements ContainerFactoryPluginInterface */ protected function getPrintEngine() { if (!isset($this->printEngine)) { - $this->printEngine = $this->pluginManager->createInstance($this->entityPrintConfig->get('print_engine')); + $this->printEngine = $this->pluginManager->createInstance($this->entityPrintConfig->get('print_engines.pdf_engine')); } return $this->printEngine; } diff --git a/src/Plugin/EntityPrint/PrintEngine/DomPdf.php b/src/Plugin/EntityPrint/PrintEngine/DomPdf.php index 4427e17..6c99a61 100644 --- a/src/Plugin/EntityPrint/PrintEngine/DomPdf.php +++ b/src/Plugin/EntityPrint/PrintEngine/DomPdf.php @@ -17,7 +17,7 @@ use Symfony\Component\HttpFoundation\Request; use Dompdf\Adapter\CPDF; /** - * @PdfEngine( + * @PrintEngine( * id = "dompdf", * label = @Translation("Dompdf"), * export_type = "pdf" @@ -34,7 +34,7 @@ class DomPdf extends PrintEngineBase implements ContainerFactoryPluginInterface /** * @var \Dompdf\Dompdf */ - protected $pdf; + protected $print; /** * Keep track of HTML pages as they're added. @@ -48,8 +48,8 @@ class DomPdf extends PrintEngineBase implements ContainerFactoryPluginInterface */ public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->pdf = new DompdfLib($this->configuration); - $this->pdf + $this->print = new DompdfLib($this->configuration); + $this->print ->setBaseHost($request->getHttpHost()) ->setProtocol($request->getScheme() . '://'); } @@ -121,14 +121,14 @@ class DomPdf extends PrintEngineBase implements ContainerFactoryPluginInterface // We must keep adding to previously added HTML as loadHtml() replaces the // entire document. $this->html .= (string) $content; - $this->pdf->loadHtml($this->html); + $this->print->loadHtml($this->html); } /** * {@inheritdoc} */ public function send($filename = NULL) { - $this->pdf->render(); + $this->print->render(); // Dompdf doesn't have a return value for send so just check the error // global it provides. @@ -140,7 +140,7 @@ class DomPdf extends PrintEngineBase implements ContainerFactoryPluginInterface // from our filename here. $filename = preg_replace('/\.pdf$/i', '', $filename); - $this->pdf->stream($filename); + $this->print->stream($filename); } /** diff --git a/src/Plugin/EntityPrint/PrintEngine/PhpWkhtmlToPdf.php b/src/Plugin/EntityPrint/PrintEngine/PhpWkhtmlToPdf.php index f96f6a7..a93dd7e 100644 --- a/src/Plugin/EntityPrint/PrintEngine/PhpWkhtmlToPdf.php +++ b/src/Plugin/EntityPrint/PrintEngine/PhpWkhtmlToPdf.php @@ -13,7 +13,7 @@ use Drupal\entity_print\Plugin\PrintEngineBase; use mikehaertl\wkhtmlto\Pdf; /** - * @PdfEngine( + * @PrintEngine( * id = "phpwkhtmltopdf", * label = @Translation("Php Wkhtmltopdf"), * export_type = "pdf" @@ -30,14 +30,14 @@ class PhpWkhtmlToPdf extends PrintEngineBase { /** * @var \mikehaertl\wkhtmlto\Pdf */ - protected $pdf; + protected $print; /** * {@inheritdoc} */ public function __construct(array $configuration, $plugin_id, $plugin_definition) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->pdf = new Pdf(['binary' => $this->configuration['binary_location']]); + $this->print = new Pdf(['binary' => $this->configuration['binary_location']]); } /** @@ -85,8 +85,8 @@ class PhpWkhtmlToPdf extends PrintEngineBase { * {@inheritdoc} */ public function send($filename = NULL) { - if (!$this->pdf->send($filename)) { - throw new PrintEngineException(sprintf('Failed to generate PDF: %s', $this->pdf->getError())); + if (!$this->print->send($filename)) { + throw new PrintEngineException(sprintf('Failed to generate PDF: %s', $this->print->getError())); } } @@ -94,7 +94,7 @@ class PhpWkhtmlToPdf extends PrintEngineBase { * {@inheritdoc} */ public function addPage($content) { - $this->pdf->addPage($content); + $this->print->addPage($content); } /**