cckPluginManager = $cck_plugin_manager; $this->fieldPluginManager = $field_plugin_manager; $this->migration = $migration; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { return new static( $configuration, $plugin_id, $plugin_definition, $container->get('plugin.manager.migrate.cckfield'), $container->get('plugin.manager.migrate.field'), $migration ); } /** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { if (!is_string($value)) { throw new MigrateException('The input value must be a string.'); } if (empty($this->configuration['method'])) { throw new MigrateException('You need to specify the name of a method to be called on the Field plugin.'); } $method = $this->configuration['method']; try { return $this->callMethodOnFieldPlugin($this->fieldPluginManager, $value, $method, $row); } catch (PluginNotFoundException $e) { try { return $this->callMethodOnFieldPlugin($this->cckPluginManager, $value, $method, $row); } catch (PluginNotFoundException $e) { return NULL; } } } /** * Instantiate a field plugin and call a method on it. * * @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_plugin_manager * The field plugin manager. * @param string $field_type * The field type for which to get the field plugin. * @param string $method * The method to call on the field plugin. * @param \Drupal\migrate\Row $row * The row from the source to process. * * @return mixed * The return value from the method called on the field plugin. */ protected function callMethodOnFieldPlugin(MigrateFieldPluginManagerInterface $field_plugin_manager, $field_type, $method, Row $row) { $plugin_id = $field_plugin_manager->getPluginIdFromFieldType($field_type, [], $this->migration); $plugin_instance = $field_plugin_manager->createInstance($plugin_id, [], $this->migration); if (!is_callable([$plugin_instance, $method])) { throw new MigrateException('The specified method does not exist or is not callable.'); } return call_user_func_array([$plugin_instance, $method], [$row]); } }