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

Overrides StaticMap::transform

File

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

Class

FilterID

Namespace

Drupal\filter\Plugin\migrate\process

Code

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;
  }
}