class ProcessField in Drupal 10
Same name and namespace in other branches
- 8 core/modules/field/src/Plugin/migrate/process/ProcessField.php \Drupal\field\Plugin\migrate\process\ProcessField
- 9 core/modules/field/src/Plugin/migrate/process/ProcessField.php \Drupal\field\Plugin\migrate\process\ProcessField
Get the value from a method call on a field plugin instance.
This process plugin will instantiate a field plugin based on the given field type and then call the given method on it for the return value.
Available configuration keys:
- source: The source field type to use to instantiate a field plugin.
- method: The method to be called on the field plugin instance.
If no field plugin for the given field type is found, NULL will be returned.
Example:
process:
type:
plugin: process_field
source: type
method: getFieldType
Plugin annotation
@MigrateProcessPlugin(
id = "process_field"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\migrate\ProcessPluginBase implements MigrateProcessInterface
- class \Drupal\field\Plugin\migrate\process\ProcessField implements ContainerFactoryPluginInterface
- class \Drupal\migrate\ProcessPluginBase implements MigrateProcessInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of ProcessField
See also
\Drupal\migrate\Plugin\MigrateProcessInterface
\Drupal\migrate_drupal\Plugin\MigrateFieldInterface;
File
- core/
modules/ field/ src/ Plugin/ migrate/ process/ ProcessField.php, line 44
Namespace
Drupal\field\Plugin\migrate\processView source
class ProcessField extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The field plugin manager.
*
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface
*/
protected $fieldPluginManager;
/**
* The migration being run.
*
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $migration;
/**
* Constructs a ProcessField plugin.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_plugin_manager
* The field plugin manager.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The migration being run.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateFieldPluginManagerInterface $field_plugin_manager, MigrationInterface $migration = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$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.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) {
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,
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 18 |
MessengerTrait:: |
public | function | Gets the messenger. | 18 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function | ||
PluginBase:: |
public | function | ||
PluginBase:: |
public | function | 2 | |
PluginBase:: |
public | function | ||
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
ProcessField:: |
protected | property | The field plugin manager. | |
ProcessField:: |
protected | property | The migration being run. | |
ProcessField:: |
protected | function | Instantiate a field plugin and call a method on it. | |
ProcessField:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
ProcessField:: |
public | function |
Performs the associated process. Overrides ProcessPluginBase:: |
|
ProcessField:: |
public | function |
Constructs a ProcessField plugin. Overrides PluginBase:: |
|
ProcessPluginBase:: |
public | function |
Indicates whether the returned value requires multiple handling. Overrides MigrateProcessInterface:: |
3 |
StringTranslationTrait:: |
protected | property | The string translation service. | 3 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 1 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |