Skip to content
Snippets Groups Projects
Commit 8f0de4d7 authored by Bernd Oliver Suenderhauf's avatar Bernd Oliver Suenderhauf
Browse files

Issue #3040900 by Pancho: Move legacy backend support incl. the JavaBridge...

Issue #3040900 by Pancho: Move legacy backend support incl. the JavaBridge ("local") backend to a submodule
parent 5c91727f
No related branches found
No related tags found
No related merge requests found
Showing
with 114 additions and 62 deletions
...@@ -193,3 +193,20 @@ function fillpdf_update_8109() { ...@@ -193,3 +193,20 @@ function fillpdf_update_8109() {
$settings->set('shell_locale', 'en_US.utf8')->save(); $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(),
]);
}
}
...@@ -3,16 +3,6 @@ services: ...@@ -3,16 +3,6 @@ services:
class: Drupal\fillpdf\Plugin\PdfBackendManager class: Drupal\fillpdf\Plugin\PdfBackendManager
parent: default_plugin_manager 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: fillpdf.link_manipulator:
class: Drupal\fillpdf\Service\FillPdfLinkManipulator class: Drupal\fillpdf\Service\FillPdfLinkManipulator
......
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
<?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.'));
}
}
}
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.
<?php <?php
namespace Drupal\fillpdf\Annotation; namespace Drupal\fillpdf_legacy\Annotation;
use Drupal\Component\Annotation\Plugin; use Drupal\Component\Annotation\Plugin;
......
<?php <?php
namespace Drupal\fillpdf\Plugin\BackendService; namespace Drupal\fillpdf_legacy\Plugin\BackendService;
use Drupal\Core\File\FileSystem; use Drupal\Core\File\FileSystem;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
......
<?php <?php
namespace Drupal\fillpdf\Plugin; namespace Drupal\fillpdf_legacy\Plugin;
use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Component\Plugin\PluginInspectionInterface;
......
<?php <?php
namespace Drupal\fillpdf\Plugin; namespace Drupal\fillpdf_legacy\Plugin;
use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\CacheBackendInterface;
...@@ -14,7 +14,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; ...@@ -14,7 +14,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
* @see https://www.drupal.org/node/3059476 * @see https://www.drupal.org/node/3059476
* @see \Drupal\fillpdf\Plugin\PdfBackendManager * @see \Drupal\fillpdf\Plugin\PdfBackendManager
*/ */
class LegacyBackendServiceManager extends DefaultPluginManager { class BackendServiceManager extends DefaultPluginManager {
/** /**
* Constructs a new LegacyBackendServiceManager object. * Constructs a new LegacyBackendServiceManager object.
...@@ -28,7 +28,7 @@ class LegacyBackendServiceManager extends DefaultPluginManager { ...@@ -28,7 +28,7 @@ class LegacyBackendServiceManager extends DefaultPluginManager {
* The module handler to invoke the alter hook with. * The module handler to invoke the alter hook with.
*/ */
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { 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->alterInfo('fillpdf_fillpdf_backend_info');
$this->setCacheBackend($cache_backend, 'fillpdf_fillpdf_backend_plugins'); $this->setCacheBackend($cache_backend, 'fillpdf_fillpdf_backend_plugins');
......
<?php <?php
namespace Drupal\fillpdf\Plugin\FillPdfBackend; namespace Drupal\fillpdf_legacy\Plugin\FillPdfBackend;
use Drupal\Core\File\FileSystem; use Drupal\Core\File\FileSystem;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
...@@ -13,10 +13,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; ...@@ -13,10 +13,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* Legacy JavaBridge FillPdfBackend plugin. * Legacy JavaBridge FillPdfBackend plugin.
* *
* @Plugin( * @Plugin(
* id = "local", * id = "local"
* label = @Translation("Local PHP/Java-Bridge"),
* description = @Translation("Legacy. Use FillPDF LocalServer instead."),
* weight = 10
* ) * )
* *
* @deprecated in fillpdf:8.x-4.9 and is removed from fillpdf:8.x-5.0. * @deprecated in fillpdf:8.x-4.9 and is removed from fillpdf:8.x-5.0.
......
<?php <?php
namespace Drupal\fillpdf\Plugin; namespace Drupal\fillpdf_legacy\Plugin;
use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleHandlerInterface;
...@@ -14,10 +14,10 @@ use Drupal\Core\Plugin\DefaultPluginManager; ...@@ -14,10 +14,10 @@ use Drupal\Core\Plugin\DefaultPluginManager;
* @see https://www.drupal.org/node/3059476 * @see https://www.drupal.org/node/3059476
* @see \Drupal\fillpdf\Plugin\PdfBackendManager * @see \Drupal\fillpdf\Plugin\PdfBackendManager
*/ */
class LegacyFillPdfBackendManager extends DefaultPluginManager { class FillPdfBackendManager extends DefaultPluginManager {
/** /**
* Constructs a LegacyFillPdfBackendManager object. * Constructs a FillPdfBackendManager object.
* *
* @param \Traversable $namespaces * @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths * An object that implements \Traversable which contains the root paths
...@@ -34,25 +34,4 @@ class LegacyFillPdfBackendManager extends DefaultPluginManager { ...@@ -34,25 +34,4 @@ class LegacyFillPdfBackendManager extends DefaultPluginManager {
$this->setCacheBackend($cache_backend, 'fillpdf_backend_info_plugins'); $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;
}
} }
<?php <?php
namespace Drupal\fillpdf\Plugin\PdfBackend; namespace Drupal\fillpdf_legacy\Plugin\PdfBackend;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\file\FileInterface; use Drupal\file\FileInterface;
use Drupal\fillpdf\Entity\FillPdfForm; use Drupal\fillpdf\Entity\FillPdfForm;
use Drupal\fillpdf\FieldMapping\ImageFieldMapping; use Drupal\fillpdf\FieldMapping\ImageFieldMapping;
use Drupal\fillpdf\FieldMapping\TextFieldMapping; use Drupal\fillpdf\FieldMapping\TextFieldMapping;
use Drupal\fillpdf\Plugin\LegacyFillPdfBackendManager; use Drupal\fillpdf_legacy\Plugin\FillPdfBackendManager;
use Drupal\fillpdf\Plugin\PdfBackendBase; use Drupal\fillpdf\Plugin\PdfBackendBase;
use Drupal\fillpdf\FillPdfBackendPluginInterface; use Drupal\fillpdf\FillPdfBackendPluginInterface;
use Drupal\fillpdf\FillPdfFormInterface; use Drupal\fillpdf\FillPdfFormInterface;
...@@ -45,10 +45,10 @@ final class LegacyProviderPdfBackend extends PdfBackendBase implements Container ...@@ -45,10 +45,10 @@ final class LegacyProviderPdfBackend extends PdfBackendBase implements Container
* The plugin_id for the plugin instance. * The plugin_id for the plugin instance.
* @param array $plugin_definition * @param array $plugin_definition
* The plugin implementation 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. * 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); parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->legacyBackend = $legacy_backend_manager->createInstance($configuration['backend'], $configuration); $this->legacyBackend = $legacy_backend_manager->createInstance($configuration['backend'], $configuration);
} }
......
<?php <?php
namespace Drupal\Tests\fillpdf\Kernel; namespace Drupal\Tests\fillpdf_legacy\Kernel;
use Drupal\Tests\fillpdf\Kernel\FillPdfKernelTestBase;
/** /**
* Tests that backend-related functions work. * Tests that backend-related functions work.
* *
* @group fillpdf * @group fillpdf
* @legacy
*/ */
class FillPdfBackendTest extends FillPdfKernelTestBase { class LegacyBackendTest extends FillPdfKernelTestBase {
public function testTestBackend() { public function testTestBackend() {
$backend_manager = $this->container->get('plugin.manager.fillpdf.pdf_backend'); $backend_manager = $this->container->get('plugin.manager.fillpdf.pdf_backend');
$test_backend = $backend_manager->createInstance('test'); $test_backend = $backend_manager->createInstance('test');
self::assertEquals('Drupal\fillpdf\Plugin\PdfBackend\LegacyProviderPdfBackend', get_class($test_backend)); self::assertEquals('Drupal\fillpdf_legacy\Plugin\PdfBackend\LegacyProviderPdfBackend', get_class($test_backend));
} }
} }
...@@ -361,15 +361,6 @@ class FillPdfSettingsForm extends ConfigFormBase { ...@@ -361,15 +361,6 @@ class FillPdfSettingsForm extends ConfigFormBase {
$form_state->setErrorByName('pdftk_path', $error_message); $form_state->setErrorByName('pdftk_path', $error_message);
} }
break; 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']; $template_scheme = $values['template_scheme'];
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\fillpdf\Plugin; namespace Drupal\fillpdf\Plugin;
use Drupal\Component\Plugin\PluginBase; use Drupal\Component\Plugin\PluginBase;
use Drupal\fillpdf_legacy\Plugin\BackendServiceInterface;
/** /**
* Base class for FillPDF BackendService plugins. * Base class for FillPDF BackendService plugins.
......
...@@ -41,9 +41,8 @@ class PdfBackendManager extends DefaultPluginManager implements FallbackPluginMa ...@@ -41,9 +41,8 @@ class PdfBackendManager extends DefaultPluginManager implements FallbackPluginMa
// Get all plugin definitions of this type. // Get all plugin definitions of this type.
$definitions = parent::getDefinitions(); $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. // @todo Remove in fillpdf:8.x-5.x.
$definitions += \Drupal::service('plugin.manager.fillpdf_backend')->getDefinitions();
unset($definitions['legacy_provider']); unset($definitions['legacy_provider']);
// Sort plugins by weight. // Sort plugins by weight.
......
...@@ -5,4 +5,4 @@ core: 8.x ...@@ -5,4 +5,4 @@ core: 8.x
package: Testing package: Testing
version: VERSION version: VERSION
dependencies: dependencies:
- fillpdf:fillpdf - fillpdf:fillpdf_legacy
...@@ -69,7 +69,7 @@ class UninstallTest extends BrowserTestBase { ...@@ -69,7 +69,7 @@ class UninstallTest extends BrowserTestBase {
$this->assertSession()->pageTextContains('There are 0 fillpdf form field entities to delete'); $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. // 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->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->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'); $this->drupalPostForm(NULL, [], 'Uninstall');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment