diff --git a/core/modules/filter/migration_templates/d6_filter_format.yml b/core/modules/filter/migration_templates/d6_filter_format.yml index 6b767f2..b0fb468 100644 --- a/core/modules/filter/migration_templates/d6_filter_format.yml +++ b/core/modules/filter/migration_templates/d6_filter_format.yml @@ -15,9 +15,10 @@ process: source: filters key: '@id' process: - id: - plugin: static_map - default_value: filter_null + id:g + # Because the bypass flag is not set, the row will be skipped + # entirely if the filter ID cannot be determined. + plugin: filter_id source: - module - delta diff --git a/core/modules/filter/migration_templates/d7_filter_format.yml b/core/modules/filter/migration_templates/d7_filter_format.yml index 2b44a80..c0710b5 100644 --- a/core/modules/filter/migration_templates/d7_filter_format.yml +++ b/core/modules/filter/migration_templates/d7_filter_format.yml @@ -15,11 +15,16 @@ process: key: '@id' process: id: - plugin: static_map + # If the filter ID cannot be mapped, it will pass through unmodified + # because the bypass flag is set. When the user actually tries to + # view text through an invalid filter plugin, the filter system will + # fall back to filter_null and display a helpful error message. + plugin: filter_id bypass: true source: name - map: - php_code: filter_null + # No need to map anything -- filter plugin IDs haven't changed since + # Drupal 7. + map: { } settings: plugin: filter_settings source: settings diff --git a/core/modules/filter/src/Plugin/migrate/process/FilterID.php b/core/modules/filter/src/Plugin/migrate/process/FilterID.php new file mode 100644 index 0000000..a29df0f --- /dev/null +++ b/core/modules/filter/src/Plugin/migrate/process/FilterID.php @@ -0,0 +1,78 @@ +filterManager = $filter_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('plugin.manager.filter') + ); + } + + /** + * {@inheritdoc} + */ + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + $plugin_id = parent::transform($value, $migrate_executable, $row, $destination_property); + + // Try to create an instance of the filter to ensure that it actually + // exists. If it doesn't, the filter manager will throw an exception, + // which we'll catch and log so as to inform the user that they've tried + // to migrate an invalid filter. But we'll let the invalid value pass + // through anyway -- the filter system will fall back to filter_null and + // the user can deal with it later. + try { + $this->filterManager->createInstance($plugin_id); + } + catch (PluginNotFoundException $e) { + $migrate_executable->saveMessage($e->getMessage()); + } + + return $plugin_id; + } + +} diff --git a/core/modules/filter/tests/src/Kernel/Migrate/d6/MigrateFilterFormatTest.php b/core/modules/filter/tests/src/Kernel/Migrate/d6/MigrateFilterFormatTest.php index ed5f0fb..3b2e8d7 100644 --- a/core/modules/filter/tests/src/Kernel/Migrate/d6/MigrateFilterFormatTest.php +++ b/core/modules/filter/tests/src/Kernel/Migrate/d6/MigrateFilterFormatTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\filter\Kernel\Migrate\d6; use Drupal\filter\Entity\FilterFormat; +use Drupal\filter\FilterFormatInterface; use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase; /** @@ -39,14 +40,16 @@ public function testFilterFormat() { $this->assertFalse(isset($filters['filter_html_image_secure'])); // Check variables migrated into filter. - $this->assertIdentical('