You are here

public function FilterID::transform in Drupal 8

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

Performs the associated process.

Parameters

mixed $value: The value to be transformed.

\Drupal\migrate\MigrateExecutableInterface $migrate_executable: The migration in which this process is being executed.

\Drupal\migrate\Row $row: The row from the source to process. Normally, just transforming the value is adequate but very rarely you might need to change two columns at the same time or something like that.

string $destination_property: The destination property currently worked on. This is only used together with the $row above.

Return value

string|array The newly transformed value.

Overrides StaticMap::transform

File

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

Class

FilterID
Plugin annotation @MigrateProcessPlugin( id = "filter_id" )

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);
      throw new MigrateSkipProcessException("The transformation-only filter {$plugin_id} was skipped.");
    }
    $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;
  }
}