From dfb5d04ecc4a6f2d62327619f270ba95dc59d8b3 Mon Sep 17 00:00:00 2001 From: Kevin Kaland <kevin@wizonesolutions.com> Date: Wed, 25 Nov 2015 12:45:29 +0100 Subject: [PATCH] Issue #2359213: Make proper method to get PDFtk path. --- src/Component/Utility/FillPdf.php | 2 ++ src/Form/FillpdfSettingsForm.php | 2 +- .../FillPdfBackend/PdftkFillPdfBackend.php | 23 +++++++------------ src/Service/FillPdfAdminFormHelper.php | 19 ++++++++++++++- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/Component/Utility/FillPdf.php b/src/Component/Utility/FillPdf.php index e768408..30b26b0 100644 --- a/src/Component/Utility/FillPdf.php +++ b/src/Component/Utility/FillPdf.php @@ -29,6 +29,8 @@ class FillPdf { * * @param $view_name * @param string $display_id + * + * @see views_embed_view() */ public static function embedView($name, $display_id = 'default') { $args = func_get_args(); diff --git a/src/Form/FillpdfSettingsForm.php b/src/Form/FillpdfSettingsForm.php index 6560609..e4dd3b0 100644 --- a/src/Form/FillpdfSettingsForm.php +++ b/src/Form/FillpdfSettingsForm.php @@ -63,7 +63,7 @@ class FillPdfSettingsForm extends ConfigFormBase { } // Check for pdftk. - $status = FillPdf::checkPdftkPath(fillpdf_pdftk_path()); + $status = FillPdf::checkPdftkPath($this->adminFormHelper->getPdftkPath()); if ($status === FALSE) { $options['pdftk'] .= '<div class="messages warning">' . $this->t('pdftk is not properly installed.') . '</div>'; } diff --git a/src/Plugin/FillPdfBackend/PdftkFillPdfBackend.php b/src/Plugin/FillPdfBackend/PdftkFillPdfBackend.php index e5a7cd9..7f6629d 100644 --- a/src/Plugin/FillPdfBackend/PdftkFillPdfBackend.php +++ b/src/Plugin/FillPdfBackend/PdftkFillPdfBackend.php @@ -7,7 +7,6 @@ namespace Drupal\fillpdf\Plugin\FillPdfBackend; use Drupal\Component\Annotation\Plugin; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Annotation\Translation; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\File\FileSystem; @@ -16,6 +15,7 @@ use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\file\Entity\File; use Drupal\file\FileInterface; use Drupal\fillpdf\Component\Utility\FillPdf; +use Drupal\fillpdf\FillPdfAdminFormHelperInterface; use Drupal\fillpdf\FillPdfBackendPluginInterface; use Drupal\fillpdf\FillPdfFormInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -36,17 +36,17 @@ class PdftkFillPdfBackend implements FillPdfBackendPluginInterface, ContainerFac /** @var \Drupal\Core\File\FileSystem */ protected $fileSystem; - /** @var \Drupal\Core\Config\ConfigFactoryInterface */ - protected $configFactory; + /** @var \Drupal\fillpdf\FillPdfAdminFormHelperInterface */ + protected $adminFormHelper; - public function __construct(FileSystem $file_system, ConfigFactoryInterface $config, array $configuration, $plugin_id, $plugin_definition) { + public function __construct(FileSystem $file_system, FillPdfAdminFormHelperInterface $admin_form_helper, array $configuration, $plugin_id, $plugin_definition) { $this->configuration = $configuration; $this->fileSystem = $file_system; - $this->configFactory = $config; + $this->adminFormHelper = $admin_form_helper; } public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static($container->get('file_system'), $container->get('config.factory'), $configuration, $plugin_id, $plugin_definition); + return new static($container->get('file_system'), $container->get('fillpdf.admin_form_helper'), $configuration, $plugin_id, $plugin_definition); } /** @@ -83,7 +83,7 @@ class PdftkFillPdfBackend implements FillPdfBackendPluginInterface, ContainerFac // Build the fields array $fields = []; $fieldindex = -1; - foreach ($output as $line => $lineitem) { + foreach ($output as $lineitem) { if ($lineitem == '---') { $fieldindex++; continue; @@ -102,14 +102,7 @@ class PdftkFillPdfBackend implements FillPdfBackendPluginInterface, ContainerFac * @return array|mixed|null|string */ protected function getPdftkPath() { - $path_to_pdftk = $this->configFactory->get('fillpdf.settings') - ->get('pdftk_path'); - - if (empty($path_to_pdftk)) { - $path_to_pdftk = 'pdftk'; - return $path_to_pdftk; - } - return $path_to_pdftk; + return $this->adminFormHelper->getPdftkPath(); } /** diff --git a/src/Service/FillPdfAdminFormHelper.php b/src/Service/FillPdfAdminFormHelper.php index 8b0edf2..de93550 100644 --- a/src/Service/FillPdfAdminFormHelper.php +++ b/src/Service/FillPdfAdminFormHelper.php @@ -6,6 +6,7 @@ namespace Drupal\fillpdf\Service; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\fillpdf\FillPdfAdminFormHelperInterface; @@ -14,8 +15,12 @@ class FillPdfAdminFormHelper implements FillPdfAdminFormHelperInterface { /** @var ModuleHandlerInterface $module_handler */ protected $moduleHandler; - public function __construct(ModuleHandlerInterface $module_handler) { + /** @var \Drupal\Core\Config\ConfigFactoryInterface */ + protected $configFactory; + + public function __construct(ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory) { $this->moduleHandler = $module_handler; + $this->configFactory = $config_factory; } /** @@ -54,4 +59,16 @@ class FillPdfAdminFormHelper implements FillPdfAdminFormHelperInterface { been used. <p>Note that omitting the <em>replacement value</em> will replace <em>original value</em> with a blank, essentially erasing it.</p>'); } + + public function getPdftkPath() { + $path_to_pdftk = $this->configFactory->get('fillpdf.settings') + ->get('pdftk_path'); + + if (empty($path_to_pdftk)) { + $path_to_pdftk = 'pdftk'; + return $path_to_pdftk; + } + return $path_to_pdftk; + } + } -- GitLab