3 namespace Drupal\filter\Plugin\migrate\process;
5 use Drupal\Component\Plugin\PluginManagerInterface;
6 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
7 use Drupal\Core\StringTranslation\TranslationInterface;
8 use Drupal\migrate\MigrateExecutableInterface;
9 use Drupal\migrate\Plugin\migrate\process\StaticMap;
10 use Drupal\migrate\Plugin\MigrationInterface;
11 use Drupal\migrate\Row;
12 use Symfony\Component\DependencyInjection\ContainerInterface;
15 * @MigrateProcessPlugin(
19 class FilterID extends StaticMap implements ContainerFactoryPluginInterface {
22 * The filter plugin manager.
24 * @var \Drupal\Component\Plugin\PluginManagerInterface|\Drupal\Component\Plugin\FallbackPluginManagerInterface
26 protected $filterManager;
29 * FilterID constructor.
31 * @param array $configuration
32 * Plugin configuration.
33 * @param string $plugin_id
35 * @param mixed $plugin_definition
36 * The plugin definition.
37 * @param \Drupal\Component\Plugin\PluginManagerInterface $filter_manager
38 * The filter plugin manager.
39 * @param \Drupal\Core\StringTranslation\TranslationInterface $translator
40 * (optional) The string translation service.
42 public function __construct(array $configuration, $plugin_id, $plugin_definition, PluginManagerInterface $filter_manager, TranslationInterface $translator = NULL) {
43 parent::__construct($configuration, $plugin_id, $plugin_definition);
44 $this->filterManager = $filter_manager;
45 $this->stringTranslation = $translator;
51 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
56 $container->get('plugin.manager.filter'),
57 $container->get('string_translation')
64 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
65 $plugin_id = parent::transform($value, $migrate_executable, $row, $destination_property);
67 // If the static map is bypassed on failure, the returned plugin ID will be
68 // an array if $value was. Plugin IDs cannot be arrays, so flatten it before
69 // passing it into the filter manager.
70 if (is_array($plugin_id)) {
71 $plugin_id = implode(':', $plugin_id);
74 if ($this->filterManager->hasDefinition($plugin_id)) {
78 $fallback = $this->filterManager->getFallbackPluginId($plugin_id);
80 $message = $this->t('Filter @plugin_id could not be mapped to an existing filter plugin; defaulting to @fallback.', [
81 '@plugin_id' => $plugin_id,
82 '@fallback' => $fallback,
84 $migrate_executable->saveMessage((string) $message, MigrationInterface::MESSAGE_WARNING);