diff --git a/core/modules/filter/migration_templates/d6_filter_format.yml b/core/modules/filter/migration_templates/d6_filter_format.yml index 6b767f2..1a869e2 100644 --- a/core/modules/filter/migration_templates/d6_filter_format.yml +++ b/core/modules/filter/migration_templates/d6_filter_format.yml @@ -16,8 +16,9 @@ process: key: '@id' process: id: - plugin: static_map - default_value: filter_null + # 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..193292b --- /dev/null +++ b/core/modules/filter/src/Plugin/migrate/process/FilterID.php @@ -0,0 +1,81 @@ +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); + + if ($this->filterManager->hasDefinition($plugin_id)) { + return $plugin_id; + } + else { + $fallback = $this->filterManager->getFallbackPluginId($plugin_id); + + if (is_array($value)) { + $value = implode(', ', $value); + } + $message = $this->t('Filter @id could not be mapped to an existing filter plugin; defaulting to @fallback.', [ + '@id' => $value, + '@fallback' => $fallback, + ]); + $migrate_executable->saveMessage($message, MigrationInterface::MESSAGE_WARNING); + + return $fallback; + } + } + +} 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..dcd9bf4 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,15 @@ public function testFilterFormat() { $this->assertFalse(isset($filters['filter_html_image_secure'])); // Check variables migrated into filter. - $this->assertIdentical('