diff -u b/core/modules/filter/migration_templates/d6_filter_format.yml b/core/modules/filter/migration_templates/d6_filter_format.yml --- b/core/modules/filter/migration_templates/d6_filter_format.yml +++ b/core/modules/filter/migration_templates/d6_filter_format.yml @@ -15,8 +15,10 @@ source: filters key: '@id' process: - id: - plugin: static_map + 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 @@ -27,8 +29,6 @@ - filter_url - filter_htmlcorrector - filter_html_escape - php: - - filter_null settings: plugin: filter_settings source: settings diff -u b/core/modules/filter/migration_templates/d7_filter_format.yml b/core/modules/filter/migration_templates/d7_filter_format.yml --- b/core/modules/filter/migration_templates/d7_filter_format.yml +++ b/core/modules/filter/migration_templates/d7_filter_format.yml @@ -15,13 +15,16 @@ 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: - # Change the php_code filter to filter_null; other filters can pass - # through unmodified. - 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 only in patch2: unchanged: --- /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; + } + +}