diff --git a/fillpdf.install b/fillpdf.install index cf6781ac120127ea242a4cb784723f1414012d7d..295ef24633d3b6ce53e9255238d81fed7af854e1 100644 --- a/fillpdf.install +++ b/fillpdf.install @@ -193,3 +193,20 @@ function fillpdf_update_8109() { $settings->set('shell_locale', 'en_US.utf8')->save(); } } + +/** + * Install FillPDF legacy backend sub-module. + */ +function fillpdf_update_8110() { + if (!\Drupal::moduleHandler()->moduleExists('fillpdf_legacy')) { + /** @var \Drupal\Core\Extension\ModuleInstaller $module_installer */ + $module_installer = \Drupal::service('module_installer'); + $module_installer->install(['fillpdf_legacy']); + + $base_url = \Drupal::request()->getBasePath(); + return new FormattableMarkup("Installed the <a href=':list'>FillPDF legacy backend support</a> sub-module.<br />If you're not using any legacy backends, you may safely <a href=':uninstall'>uninstall it again.</a>.", [ + ':list' => Url::fromRoute('system.modules_list', [], ['fragment' => 'module-fillpdf'])->setOption('base_url', $base_url)->toString(), + ':uninstall' => Url::fromRoute('system.modules_uninstall')->setOption('base_url', $base_url)->toString(), + ]); + } +} diff --git a/fillpdf.services.yml b/fillpdf.services.yml index 78284cdd3a01c171a8a59b8ab7c3554a599e1960..7cac75c8f30ebf18db9852cbf7d5bba6817157ea 100644 --- a/fillpdf.services.yml +++ b/fillpdf.services.yml @@ -3,16 +3,6 @@ services: class: Drupal\fillpdf\Plugin\PdfBackendManager parent: default_plugin_manager - plugin.manager.fillpdf_backend: - class: Drupal\fillpdf\Plugin\LegacyFillPdfBackendManager - parent: default_plugin_manager - deprecated: The "%service_id%" service is deprecated. You should use the 'plugin.manager.fillpdf.pdf_backend' service instead. - - plugin.manager.fillpdf_backend_service: - class: Drupal\fillpdf\Plugin\LegacyBackendServiceManager - parent: default_plugin_manager - deprecated: The "%service_id%" service is deprecated. You should use the 'plugin.manager.fillpdf.pdf_backend' service instead. - fillpdf.link_manipulator: class: Drupal\fillpdf\Service\FillPdfLinkManipulator diff --git a/modules/fillpdf_legacy/fillpdf_legacy.info.yml b/modules/fillpdf_legacy/fillpdf_legacy.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..01f5c33ae44860eacd0b717d837fb0678e1ca4c6 --- /dev/null +++ b/modules/fillpdf_legacy/fillpdf_legacy.info.yml @@ -0,0 +1,8 @@ +name: 'FillPDF legacy backend support' +type: module +description: 'Provides support to legacy backend plugins.' +core: 8.x +package: Other +configure: fillpdf.settings +dependencies: + - drupal:fillpdf diff --git a/modules/fillpdf_legacy/fillpdf_legacy.module b/modules/fillpdf_legacy/fillpdf_legacy.module new file mode 100644 index 0000000000000000000000000000000000000000..2281e665b918cd6f9e4235505e7a0fccee69013f --- /dev/null +++ b/modules/fillpdf_legacy/fillpdf_legacy.module @@ -0,0 +1,39 @@ +<?php + +use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; + +/** + * Implements hook_form_FORM_ID_alter(). + */ +function fillpdf_legacy_form_fillpdf_settings_alter(array &$form, FormStateInterface $form_state) { + $label = new TranslatableMarkup('Local PHP/JavaBridge'); + $description = new TranslatableMarkup('Legacy. Use FillPDF LocalServer instead.'); + $form['backend']['#options']['local'] = "<strong>{$label}</strong>: {$description}"; + + $form['local']['warning'] = [ + '#type' => 'item', + '#markup' => '<div class="messages messages--warning">' . new TranslatableMarkup('Please note that the Local PHP/JavaBridge backend is deprecated and will be removed from FillPDF 5.x. Use FillPDF LocalServer instead.') . '</div>', + '#states' => [ + 'visible' => [ + ':radio[name="backend"]' => ['value' => 'local'], + ], + ], + ]; + + $form['#validate'][] = '_fillpdf_legacy_form_fillpdf_settings_validate'; +} + +/** + * Extra validation handler for fillpdf_legacy_form_fillpdf_settings_alter(). + * + * @see fillpdf_legacy_form_fillpdf_settings_alter() + */ +function _fillpdf_legacy_form_fillpdf_settings_validate($form, FormStateInterface $form_state) { + if ($form_state->getValue('backend') == 'local') { + $status = file_exists(drupal_get_path('module', 'fillpdf') . '/lib/JavaBridge/java/Java.inc'); + if ($status === FALSE) { + $form_state->setError($form['backend'], new TranslatableMarkup('JavaBridge is not installed locally.')); + } + } +} diff --git a/modules/fillpdf_legacy/fillpdf_legacy.services.yml b/modules/fillpdf_legacy/fillpdf_legacy.services.yml new file mode 100644 index 0000000000000000000000000000000000000000..6fbcfe39711d9a697511ebb0bc6ad2baa2416680 --- /dev/null +++ b/modules/fillpdf_legacy/fillpdf_legacy.services.yml @@ -0,0 +1,10 @@ +services: + plugin.manager.fillpdf_backend: + class: Drupal\fillpdf_legacy\Plugin\FillPdfBackendManager + parent: default_plugin_manager + deprecated: The "%service_id%" service is deprecated. You should use the 'plugin.manager.fillpdf.pdf_backend' service instead. + + plugin.manager.fillpdf_backend_service: + class: Drupal\fillpdf_legacy\Plugin\BackendServiceManager + parent: default_plugin_manager + deprecated: The "%service_id%" service is deprecated. You should use the 'plugin.manager.fillpdf.pdf_backend' service instead. diff --git a/src/Annotation/BackendService.php b/modules/fillpdf_legacy/src/Annotation/BackendService.php similarity index 93% rename from src/Annotation/BackendService.php rename to modules/fillpdf_legacy/src/Annotation/BackendService.php index 91707fc4f54610d86b6a1531c62f9c9ccb3e791c..2b41c14049002091d17f61b5e10567b539035ed0 100644 --- a/src/Annotation/BackendService.php +++ b/modules/fillpdf_legacy/src/Annotation/BackendService.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\fillpdf\Annotation; +namespace Drupal\fillpdf_legacy\Annotation; use Drupal\Component\Annotation\Plugin; diff --git a/src/Plugin/BackendService/LocalServerBackendService.php b/modules/fillpdf_legacy/src/Plugin/BackendService/LocalServerBackendService.php similarity index 98% rename from src/Plugin/BackendService/LocalServerBackendService.php rename to modules/fillpdf_legacy/src/Plugin/BackendService/LocalServerBackendService.php index 9b704027867f5c558041940e1e09f3f49de3c096..7816760f7c017a49350602f9b85f0b464d45294a 100644 --- a/src/Plugin/BackendService/LocalServerBackendService.php +++ b/modules/fillpdf_legacy/src/Plugin/BackendService/LocalServerBackendService.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\fillpdf\Plugin\BackendService; +namespace Drupal\fillpdf_legacy\Plugin\BackendService; use Drupal\Core\File\FileSystem; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; diff --git a/src/Plugin/BackendServiceInterface.php b/modules/fillpdf_legacy/src/Plugin/BackendServiceInterface.php similarity index 98% rename from src/Plugin/BackendServiceInterface.php rename to modules/fillpdf_legacy/src/Plugin/BackendServiceInterface.php index 987726b7823db74111cf19f1960a7f8c6462a4e3..26b50c9757d341d06e0c89cba4a4eb562213d152 100644 --- a/src/Plugin/BackendServiceInterface.php +++ b/modules/fillpdf_legacy/src/Plugin/BackendServiceInterface.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\fillpdf\Plugin; +namespace Drupal\fillpdf_legacy\Plugin; use Drupal\Component\Plugin\PluginInspectionInterface; diff --git a/src/Plugin/LegacyBackendServiceManager.php b/modules/fillpdf_legacy/src/Plugin/BackendServiceManager.php similarity index 85% rename from src/Plugin/LegacyBackendServiceManager.php rename to modules/fillpdf_legacy/src/Plugin/BackendServiceManager.php index 966a98b39f5ceb5c7bc40628cb21c82b7df7f854..c0c3cc663388756bf9e22db401a1d3ea999df9ca 100644 --- a/src/Plugin/LegacyBackendServiceManager.php +++ b/modules/fillpdf_legacy/src/Plugin/BackendServiceManager.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\fillpdf\Plugin; +namespace Drupal\fillpdf_legacy\Plugin; use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\Cache\CacheBackendInterface; @@ -14,7 +14,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; * @see https://www.drupal.org/node/3059476 * @see \Drupal\fillpdf\Plugin\PdfBackendManager */ -class LegacyBackendServiceManager extends DefaultPluginManager { +class BackendServiceManager extends DefaultPluginManager { /** * Constructs a new LegacyBackendServiceManager object. @@ -28,7 +28,7 @@ class LegacyBackendServiceManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/BackendService', $namespaces, $module_handler, 'Drupal\fillpdf\Plugin\BackendServiceInterface', 'Drupal\fillpdf\Annotation\BackendService'); + parent::__construct('Plugin/BackendService', $namespaces, $module_handler, 'Drupal\fillpdf_legacy\Plugin\BackendServiceInterface', 'Drupal\fillpdf_legacy\Annotation\BackendService'); $this->alterInfo('fillpdf_fillpdf_backend_info'); $this->setCacheBackend($cache_backend, 'fillpdf_fillpdf_backend_plugins'); diff --git a/src/Plugin/FillPdfBackend/JavaBridgeFillPdfBackend.php b/modules/fillpdf_legacy/src/Plugin/FillPdfBackend/JavaBridgeFillPdfBackend.php similarity index 94% rename from src/Plugin/FillPdfBackend/JavaBridgeFillPdfBackend.php rename to modules/fillpdf_legacy/src/Plugin/FillPdfBackend/JavaBridgeFillPdfBackend.php index bb40f1f0ec1a99b6876c98e4b0fa08de81a3c9c7..5474b879c8f9378a0f61cf27b04044cc7fa38632 100644 --- a/src/Plugin/FillPdfBackend/JavaBridgeFillPdfBackend.php +++ b/modules/fillpdf_legacy/src/Plugin/FillPdfBackend/JavaBridgeFillPdfBackend.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\fillpdf\Plugin\FillPdfBackend; +namespace Drupal\fillpdf_legacy\Plugin\FillPdfBackend; use Drupal\Core\File\FileSystem; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -13,10 +13,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * Legacy JavaBridge FillPdfBackend plugin. * * @Plugin( - * id = "local", - * label = @Translation("Local PHP/Java-Bridge"), - * description = @Translation("Legacy. Use FillPDF LocalServer instead."), - * weight = 10 + * id = "local" * ) * * @deprecated in fillpdf:8.x-4.9 and is removed from fillpdf:8.x-5.0. diff --git a/src/Plugin/LegacyFillPdfBackendManager.php b/modules/fillpdf_legacy/src/Plugin/FillPdfBackendManager.php similarity index 65% rename from src/Plugin/LegacyFillPdfBackendManager.php rename to modules/fillpdf_legacy/src/Plugin/FillPdfBackendManager.php index dcef1db8c4b93b64a943fb0f1409abde78d95e00..285ebe8dac56422dd17ed3059c3bdd913ae21c59 100644 --- a/src/Plugin/LegacyFillPdfBackendManager.php +++ b/modules/fillpdf_legacy/src/Plugin/FillPdfBackendManager.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\fillpdf\Plugin; +namespace Drupal\fillpdf_legacy\Plugin; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -14,10 +14,10 @@ use Drupal\Core\Plugin\DefaultPluginManager; * @see https://www.drupal.org/node/3059476 * @see \Drupal\fillpdf\Plugin\PdfBackendManager */ -class LegacyFillPdfBackendManager extends DefaultPluginManager { +class FillPdfBackendManager extends DefaultPluginManager { /** - * Constructs a LegacyFillPdfBackendManager object. + * Constructs a FillPdfBackendManager object. * * @param \Traversable $namespaces * An object that implements \Traversable which contains the root paths @@ -34,25 +34,4 @@ class LegacyFillPdfBackendManager extends DefaultPluginManager { $this->setCacheBackend($cache_backend, 'fillpdf_backend_info_plugins'); } - /** - * Gets the definitions of all FillPDF backend plugins. - * - * @return mixed[] - * An associative array of plugin definitions, keyed by plugin ID. - */ - public function getDefinitions() { - $definitions = parent::getDefinitions(); - - foreach ($definitions as $id => $definition) { - if (!isset($definition['description'])) { - $definitions[$id]['description'] = ''; - } - if (!isset($definition['weight'])) { - $definitions[$id]['weight'] = 0; - } - } - - return $definitions; - } - } diff --git a/src/Plugin/PdfBackend/LegacyProviderPdfBackend.php b/modules/fillpdf_legacy/src/Plugin/PdfBackend/LegacyProviderPdfBackend.php similarity index 93% rename from src/Plugin/PdfBackend/LegacyProviderPdfBackend.php rename to modules/fillpdf_legacy/src/Plugin/PdfBackend/LegacyProviderPdfBackend.php index 02c9d08ce41971feef85956a59061344d6805f91..30b38dc676c19b39fca795add95089710199a304 100644 --- a/src/Plugin/PdfBackend/LegacyProviderPdfBackend.php +++ b/modules/fillpdf_legacy/src/Plugin/PdfBackend/LegacyProviderPdfBackend.php @@ -1,13 +1,13 @@ <?php -namespace Drupal\fillpdf\Plugin\PdfBackend; +namespace Drupal\fillpdf_legacy\Plugin\PdfBackend; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\file\FileInterface; use Drupal\fillpdf\Entity\FillPdfForm; use Drupal\fillpdf\FieldMapping\ImageFieldMapping; use Drupal\fillpdf\FieldMapping\TextFieldMapping; -use Drupal\fillpdf\Plugin\LegacyFillPdfBackendManager; +use Drupal\fillpdf_legacy\Plugin\FillPdfBackendManager; use Drupal\fillpdf\Plugin\PdfBackendBase; use Drupal\fillpdf\FillPdfBackendPluginInterface; use Drupal\fillpdf\FillPdfFormInterface; @@ -45,10 +45,10 @@ final class LegacyProviderPdfBackend extends PdfBackendBase implements Container * The plugin_id for the plugin instance. * @param array $plugin_definition * The plugin implementation definition. - * @param \Drupal\fillpdf\Plugin\LegacyFillPdfBackendManager $legacy_backend_manager + * @param \Drupal\fillpdf_legacy\Plugin\FillPdfBackendManager $legacy_backend_manager * The FillPDF legacy backend manager. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, LegacyFillPdfBackendManager $legacy_backend_manager) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, FillPdfBackendManager $legacy_backend_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->legacyBackend = $legacy_backend_manager->createInstance($configuration['backend'], $configuration); } diff --git a/modules/fillpdf_legacy/tests/Kernel/LegacyBackendTest.php b/modules/fillpdf_legacy/tests/Kernel/LegacyBackendTest.php new file mode 100644 index 0000000000000000000000000000000000000000..2c3748129911f17ec217a0a99634ecc4255a830a --- /dev/null +++ b/modules/fillpdf_legacy/tests/Kernel/LegacyBackendTest.php @@ -0,0 +1,21 @@ +<?php + +namespace Drupal\Tests\fillpdf_legacy\Kernel; + +use Drupal\Tests\fillpdf\Kernel\FillPdfKernelTestBase; + +/** + * Tests that backend-related functions work. + * + * @group fillpdf + * @legacy + */ +class LegacyBackendTest extends FillPdfKernelTestBase { + + public function testTestBackend() { + $backend_manager = $this->container->get('plugin.manager.fillpdf.pdf_backend'); + $test_backend = $backend_manager->createInstance('test'); + self::assertEquals('Drupal\fillpdf_legacy\Plugin\PdfBackend\LegacyProviderPdfBackend', get_class($test_backend)); + } + +} diff --git a/src/Form/FillPdfSettingsForm.php b/src/Form/FillPdfSettingsForm.php index d5a00318dfa481cd850cee0404c935994894ef67..a207f824522acd85ba0c44c5d9be9c12c6ced58a 100644 --- a/src/Form/FillPdfSettingsForm.php +++ b/src/Form/FillPdfSettingsForm.php @@ -361,15 +361,6 @@ class FillPdfSettingsForm extends ConfigFormBase { $form_state->setErrorByName('pdftk_path', $error_message); } break; - - case 'local': - // Check for JavaBridge. - $status = file_exists(drupal_get_path('module', 'fillpdf') . '/lib/JavaBridge/java/Java.inc'); - if ($status === FALSE) { - $error_message = $this->t('JavaBridge is not installed locally.'); - $form_state->setErrorByName('local', $error_message); - } - break; } $template_scheme = $values['template_scheme']; diff --git a/src/Plugin/BackendServiceBase.php b/src/Plugin/BackendServiceBase.php index 7cd4f6b8bff73c87e212e34aea1dfe900f392872..64543ee02b6f7fb3cb07772ac4f6ce5d92395e41 100644 --- a/src/Plugin/BackendServiceBase.php +++ b/src/Plugin/BackendServiceBase.php @@ -3,6 +3,7 @@ namespace Drupal\fillpdf\Plugin; use Drupal\Component\Plugin\PluginBase; +use Drupal\fillpdf_legacy\Plugin\BackendServiceInterface; /** * Base class for FillPDF BackendService plugins. diff --git a/src/Plugin/PdfBackendManager.php b/src/Plugin/PdfBackendManager.php index b229e03cfb24dbbcc2ff3410d71d8ef4c3487d9f..f7bb434731cb2bf62e89649325607fd8d247ce42 100644 --- a/src/Plugin/PdfBackendManager.php +++ b/src/Plugin/PdfBackendManager.php @@ -41,9 +41,8 @@ class PdfBackendManager extends DefaultPluginManager implements FallbackPluginMa // Get all plugin definitions of this type. $definitions = parent::getDefinitions(); - // Add legacy plugin definitions, but unset the legacy plugin provider. + // Unset the legacy plugin provider. // @todo Remove in fillpdf:8.x-5.x. - $definitions += \Drupal::service('plugin.manager.fillpdf_backend')->getDefinitions(); unset($definitions['legacy_provider']); // Sort plugins by weight. diff --git a/tests/modules/fillpdf_test/fillpdf_test.info.yml b/tests/modules/fillpdf_test/fillpdf_test.info.yml index e1ca9b8b13e412785965b5f2e4a46a5b2d46793e..904c3185b1b04ee26ec22e43e85c61bb26993339 100644 --- a/tests/modules/fillpdf_test/fillpdf_test.info.yml +++ b/tests/modules/fillpdf_test/fillpdf_test.info.yml @@ -5,4 +5,4 @@ core: 8.x package: Testing version: VERSION dependencies: - - fillpdf:fillpdf + - fillpdf:fillpdf_legacy diff --git a/tests/src/Functional/UninstallTest.php b/tests/src/Functional/UninstallTest.php index a34e7a42a5b3e04878a77654901b215d8e66ed6a..63da2256b4000b2142efc971e75defa9cc19e169 100644 --- a/tests/src/Functional/UninstallTest.php +++ b/tests/src/Functional/UninstallTest.php @@ -69,7 +69,7 @@ class UninstallTest extends BrowserTestBase { $this->assertSession()->pageTextContains('There are 0 fillpdf form field entities to delete'); // Now go back to the uninstall page and uninstall fillpdf_test and fillpdf. - foreach (['fillpdf_test', 'fillpdf'] as $module) { + foreach (['fillpdf_test', 'fillpdf_legacy', 'fillpdf'] as $module) { $this->drupalPostForm(Url::fromRoute('system.modules_uninstall'), ["uninstall[$module]" => TRUE], 'Uninstall'); $this->assertSession()->pageTextContains('The following modules will be completely uninstalled from your site, and all data from these modules will be lost'); $this->drupalPostForm(NULL, [], 'Uninstall'); diff --git a/tests/src/Kernel/FillPdfBackendTest.php b/tests/src/Kernel/FillPdfBackendTest.php deleted file mode 100644 index 09440cf3e24197de479a9cf0b92b980b53369cfe..0000000000000000000000000000000000000000 --- a/tests/src/Kernel/FillPdfBackendTest.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -namespace Drupal\Tests\fillpdf\Kernel; - -/** - * Tests that backend-related functions work. - * - * @group fillpdf - */ -class FillPdfBackendTest extends FillPdfKernelTestBase { - - public function testTestBackend() { - $backend_manager = $this->container->get('plugin.manager.fillpdf.pdf_backend'); - $test_backend = $backend_manager->createInstance('test'); - self::assertEquals('Drupal\fillpdf\Plugin\PdfBackend\LegacyProviderPdfBackend', get_class($test_backend)); - } - -}