diff --git a/src/Component/Utility/FillPdf.php b/src/Component/Utility/FillPdf.php index e7684086b103aed93bd6b28501d275418fb584de..30b26b083619854c98d83eb2a36b92bfcd352f72 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 65606091aa9de2d872cd6b1d17e8f8c0bb5afb9f..e4dd3b0fcceef4610c026b3426537db8595a52a4 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 e5a7cd99b157c23962daf865f26420bfedf111b8..7f6629df04e3ea013295b9c4da9da167ef115506 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 8b0edf2161930c640e5a3987a860887a12c9beec..de93550cef0126d652408417d11c3395c09d910c 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; + } + }