Same name and namespace in other branches
- 8.9.x core/modules/migrate/src/Plugin/migrate/process/Get.php \Drupal\migrate\Plugin\migrate\process\Get
- 9 core/modules/migrate/src/Plugin/migrate/process/Get.php \Drupal\migrate\Plugin\migrate\process\Get
Gets the source value.
Available configuration keys:
- source: Source property.
The get plugin returns the value of the property given by the "source" configuration key.
Examples:
process:
bar:
plugin: get
source: foo
This copies the source value of foo to the destination property "bar".
Since get is the default process plugin, it can be shorthanded like this:
process:
bar:
foo;
Get also supports a list of source properties.
Example:
process:
bar:
plugin: get
source:
- foo1
- foo2
This copies the array of source values [foo1, foo2] to the destination property "bar".
If the list of source properties contains an empty element then the current value will be used. This makes it impossible to reach a source property with an empty string as its name.
Get also supports copying destination values. These are indicated by a starting @ sign. Values using @ must be wrapped in quotes.
process:
foo:
plugin: machine_name
source: baz
bar:
plugin: get
source: '@foo'
This will simply copy the destination value of foo to the destination property bar. foo configuration is included for illustration purposes.
Because of this, if the source or destination property actually starts with a "@", that character must be escaped with "@@". The referenced property becomes, for example, "@@@foo".
process:
'@foo':
plugin: machine_name
source: baz
bar:
plugin: get
source: '@@@foo'
This should occur extremely rarely.
Plugin annotation
@MigrateProcessPlugin(
id = "get",
handle_multiples = TRUE
)
Hierarchy
- class \Drupal\migrate\Plugin\migrate\process\Get extends \Drupal\migrate\ProcessPluginBase
Expanded class hierarchy of Get
See also
\Drupal\migrate\Plugin\MigrateProcessInterface
1 file declares its use of Get
- GetTest.php in core/
modules/ migrate/ tests/ src/ Unit/ process/ GetTest.php
File
- core/
modules/ migrate/ src/ Plugin/ migrate/ process/ Get.php, line 95
Namespace
Drupal\migrate\Plugin\migrate\processView source
class Get extends ProcessPluginBase {
/**
* Flag indicating whether there are multiple values.
*
* @var bool
*/
protected $multiple;
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$source = $this->configuration['source'];
$properties = is_string($source) ? [
$source,
] : $source;
$return = [];
foreach ($properties as $property) {
if ($property || (string) $property === '0') {
$return[] = $row
->get($property);
}
else {
$return[] = $value;
}
}
if (is_string($source)) {
$this->multiple = is_array($return[0]);
return $return[0];
}
return $return;
}
/**
* {@inheritdoc}
*/
public function multiple() {
return $this->multiple;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Get:: |
public | function | ||
Get:: |
public | function | ||
Get:: |
protected | property | Flag indicating whether there are multiple values. |