3 namespace Drupal\migrate\Plugin\migrate\process;
5 use Drupal\migrate\ProcessPluginBase;
6 use Drupal\migrate\MigrateExecutableInterface;
7 use Drupal\migrate\Row;
10 * Gets the source value.
12 * Available configuration keys:
13 * - source: Source property.
15 * The get plugin returns the value of the property given by the "source"
27 * This copies the source value of foo to the destination property "bar".
29 * Since get is the default process plugin, it can be shorthanded like this:
36 * Get also supports a list of source properties.
49 * This copies the array of source values [foo1, foo2] to the destination
52 * If the list of source properties contains an empty element then the current
53 * value will be used. This makes it impossible to reach a source property with
54 * an empty string as its name.
56 * Get also supports copying destination values. These are indicated by a
57 * starting @ sign. Values using @ must be wrapped in quotes.
62 * plugin: machine_name
69 * This will simply copy the destination value of foo to the destination
70 * property bar. foo configuration is included for illustration purposes.
72 * Because of this, if the source or destination property actually starts with a
73 * @, that character must be escaped with @@.
74 * The referenced property becomes, for example, @@@foo.
79 * plugin: machine_name
86 * This should occur extremely rarely.
88 * @see \Drupal\migrate\Plugin\MigrateProcessInterface
90 * @MigrateProcessPlugin(
94 class Get extends ProcessPluginBase {
97 * Flag indicating whether there are multiple values.
106 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
107 $source = $this->configuration['source'];
108 $properties = is_string($source) ? [$source] : $source;
110 foreach ($properties as $property) {
111 if ($property || (string) $property === '0') {
113 if ($property[0] == '@') {
114 $property = preg_replace_callback('/^(@?)((?:@@)*)([^@]|$)/', function ($matches) use (&$is_source) {
115 // If there are an odd number of @ in the beginning, it's a
117 $is_source = empty($matches[1]);
118 // Remove the possible escaping and do not lose the terminating
120 return str_replace('@@', '@', $matches[2]) . $matches[3];
124 $return[] = $row->getSourceProperty($property);
127 $return[] = $row->getDestinationProperty($property);
135 if (is_string($source)) {
136 $this->multiple = is_array($return[0]);
145 public function multiple() {
146 return $this->multiple;