class FilterID

Same name and namespace in other branches
  1. 10 core/modules/filter/src/Plugin/migrate/process/FilterID.php \Drupal\filter\Plugin\migrate\process\FilterID
  2. 9 core/modules/filter/src/Plugin/migrate/process/FilterID.php \Drupal\filter\Plugin\migrate\process\FilterID
  3. 8.9.x core/modules/filter/src/Plugin/migrate/process/FilterID.php \Drupal\filter\Plugin\migrate\process\FilterID

Determines the filter ID.

Attributes

#[MigrateProcess('filter_id')]

Hierarchy

Expanded class hierarchy of FilterID

1 file declares its use of FilterID
FilterIdTest.php in core/modules/filter/tests/src/Kernel/Plugin/migrate/process/FilterIdTest.php

File

core/modules/filter/src/Plugin/migrate/process/FilterID.php, line 25

Namespace

Drupal\filter\Plugin\migrate\process
View source
class FilterID extends StaticMap implements ContainerFactoryPluginInterface {
  
  /**
   * The filter plugin manager.
   *
   * @var \Drupal\Component\Plugin\PluginManagerInterface|\Drupal\Component\Plugin\FallbackPluginManagerInterface
   */
  protected $filterManager;
  
  /**
   * FilterID constructor.
   *
   * @param array $configuration
   *   Plugin configuration.
   * @param string $plugin_id
   *   The plugin ID.
   * @param mixed $plugin_definition
   *   The plugin definition.
   * @param \Drupal\Component\Plugin\PluginManagerInterface $filter_manager
   *   The filter plugin manager.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $translator
   *   (optional) The string translation service.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, PluginManagerInterface $filter_manager, ?TranslationInterface $translator = NULL) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->filterManager = $filter_manager;
    $this->stringTranslation = $translator;
  }
  
  /**
   * {@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'), $container->get('string_translation'));
  }
  
  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    $plugin_id = parent::transform($value, $migrate_executable, $row, $destination_property);
    // If the static map is bypassed on failure, the returned plugin ID will be
    // an array if $value was. Plugin IDs cannot be arrays, so flatten it before
    // passing it into the filter manager.
    if (is_array($plugin_id)) {
      $plugin_id = implode(':', $plugin_id);
    }
    if ($this->filterManager
      ->hasDefinition($plugin_id)) {
      return $plugin_id;
    }
    else {
      if (in_array(static::getSourceFilterType($value), [
        FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
        FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      ], TRUE)) {
        $message = sprintf('Filter %s could not be mapped to an existing filter plugin; omitted since it is a transformation-only filter. Install and configure a successor after the migration.', $plugin_id);
        $migrate_executable->saveMessage($message, MigrationInterface::MESSAGE_INFORMATIONAL);
        $this->stopPipeline();
        return NULL;
      }
      $fallback = $this->filterManager
        ->getFallbackPluginId($plugin_id);
      // @see \Drupal\filter\Plugin\migrate\process\FilterSettings::transform()
      $message = sprintf('Filter %s could not be mapped to an existing filter plugin; defaulting to %s and dropping all settings. Either redo the migration with the module installed that provides an equivalent filter, or modify the text format after the migration to remove this filter if it is no longer necessary.', $plugin_id, $fallback);
      $migrate_executable->saveMessage($message, MigrationInterface::MESSAGE_WARNING);
      return $fallback;
    }
  }
  
  /**
   * Gets the Drupal 8 filter type for a Drupal 7 filter.
   *
   * @param string $filter_id
   *   A Drupal 7 filter ID.
   *
   * @return int
   *   One of:
   *   - FilterInterface::TYPE_MARKUP_LANGUAGE
   *   - FilterInterface::TYPE_HTML_RESTRICTOR
   *   - FilterInterface::TYPE_TRANSFORM_REVERSIBLE
   *   - FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE
   *
   * @see \Drupal\filter\Plugin\FilterInterface::getType()
   */
  protected static function getSourceFilterType($filter_id) {
    // Drupal 7 core filters.
    // - https://git.drupalcode.org/project/drupal/blob/7.69/modules/filter/filter.module#L1229
    // - https://git.drupalcode.org/project/drupal/blob/7.69/modules/php/php.module#L139
    return match ($filter_id) {  'filter_html' => FilterInterface::TYPE_HTML_RESTRICTOR,
      'filter_url' => FilterInterface::TYPE_MARKUP_LANGUAGE,
      'filter_autop' => FilterInterface::TYPE_MARKUP_LANGUAGE,
      'filter_htmlcorrector' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'filter_html_escape' => FilterInterface::TYPE_HTML_RESTRICTOR,
      'php_code' => FilterInterface::TYPE_MARKUP_LANGUAGE,
      'abbrfilter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'ace_editor' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'adsense' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'api_filter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'api_tokens' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'filter_autofloat' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'bbcode' => FilterInterface::TYPE_MARKUP_LANGUAGE,
      'biblio_filter_reference', 'biblio_filter_inline_reference' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'caption' => FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
      'caption_filter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'filter_cincopa' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'ckeditor_blocks' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'ckeditor_filter' => FilterInterface::TYPE_HTML_RESTRICTOR,
      'ckeditor_link_filter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'ckeditor_swf_filter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'codefilter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'collapse_text_filter' => FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
      'columns_filter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'commonmark' => FilterInterface::TYPE_MARKUP_LANGUAGE,
      'filter_hashtags' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'deepzoom' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'editor_align', 'editor_caption' => FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
      'elf' => FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
      'filter_emogrifier' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'emptyparagraphkiller' => FilterInterface::TYPE_HTML_RESTRICTOR,
      'entity_embed' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'filter_align' => FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
      'ext_link_page' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'filter_html_image_secure' => FilterInterface::TYPE_HTML_RESTRICTOR,
      'filter_transliteration' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'flickr_filter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'float_filter' => FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
      'filter_footnotes' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'forena_report' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'filter_g2' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'geo_filter_filter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'filter_google_analytics_counter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'filter_google_analytics_referrer' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'gotwo_link' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'h5p_content' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'highlight_js' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'htmLawed' => FilterInterface::TYPE_HTML_RESTRICTOR,
      'htmlpurifier_basic', 'htmlpurifier_advanced' => FilterInterface::TYPE_HTML_RESTRICTOR,
      'htmltidy' => FilterInterface::TYPE_HTML_RESTRICTOR,
      'icon_filter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'iframe' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'image_resize_filter' => FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
      'insert_view' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'intlinks title', 'intlinks hide bad' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'accordion', 'dialog', 'tabs' => FilterInterface::TYPE_MARKUP_LANGUAGE,
      'language_sections' => FilterInterface::TYPE_MARKUP_LANGUAGE,
      'lazy_filter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'lazyloader_filter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'filter_link_node' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'linktitle' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'filter_markdown' => FilterInterface::TYPE_MARKUP_LANGUAGE,
      'media_filter', 'media_filter_paragraph_fix' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'filter_mentions' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'menu_filter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'mobile_codes' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'multicolumn' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'multilink_filter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'mytube' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'node_embed' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'node_field_embed' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'external_links' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'noreferrer' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'oembed', 'oembed_legacy' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'office_html_strip' => FilterInterface::TYPE_HTML_RESTRICTOR,
      'office_html_convert' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'openlayers' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'opengraph_filter' => FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
      'pathologic' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'popup_tags' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'prettify' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'rel_to_abs' => FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
      'rollover_filter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'sanitizable' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'smart_paging_filter', 'smart_paging_filter_autop' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'spamspan' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'mee_scald_widgets' => FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
      'script_filter' => FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
      'shortcode' => FilterInterface::TYPE_MARKUP_LANGUAGE,
      'shortcode_text_corrector' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'smiley' => FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
      'filter_svg_embed' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'spoiler' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'filter_toc' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'filter_tables' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'target_filter_url' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'textile' => FilterInterface::TYPE_MARKUP_LANGUAGE,
      'theme_filter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'filter_tokens' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'transliteration' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'typogrify' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'uuid_link_filter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'wysiwyg', 'wysiwyg_template_cleanup' => FilterInterface::TYPE_HTML_RESTRICTOR,
      'word_link' => FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
      'wordfilter' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
      'xbbcode' => FilterInterface::TYPE_MARKUP_LANGUAGE,
      default => NULL,
    
    };
  }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FilterID::$filterManager protected property The filter plugin manager.
FilterID::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
FilterID::getSourceFilterType protected static function Gets the Drupal 8 filter type for a Drupal 7 filter.
FilterID::transform public function Performs the associated process. Overrides StaticMap::transform
FilterID::__construct public function FilterID constructor. Overrides PluginBase::__construct
MessengerTrait::$messenger protected property The messenger. 25
MessengerTrait::messenger public function Gets the messenger. 25
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin ID.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin ID of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable Deprecated public function Determines if the plugin is configurable.
ProcessPluginBase::$stopPipeline protected property Determines if processing of the pipeline is stopped.
ProcessPluginBase::isPipelineStopped public function Determines if the pipeline should stop processing. Overrides MigrateProcessInterface::isPipelineStopped
ProcessPluginBase::multiple public function Indicates whether the returned value requires multiple handling. Overrides MigrateProcessInterface::multiple 3
ProcessPluginBase::reset public function Resets the internal data of a plugin. Overrides MigrateProcessInterface::reset
ProcessPluginBase::stopPipeline protected function Stops pipeline processing after this plugin finishes.
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.