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 your source or destination property actually starts with
73 * a @ you need to double those starting characters up. This means that if a
74 * destination property happens to start with a @ and you want to refer it,
75 * you'll need to start with three @ characters -- one to indicate the
76 * destination and two for escaping the real @.
81 * plugin: machine_name
88 * This should occur extremely rarely.
90 * @see \Drupal\migrate\Plugin\MigrateProcessInterface
92 * @MigrateProcessPlugin(
96 class Get extends ProcessPluginBase {
99 * Flag indicating whether there are multiple values.
108 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
109 $source = $this->configuration['source'];
110 $properties = is_string($source) ? [$source] : $source;
112 foreach ($properties as $property) {
113 if ($property || (string) $property === '0') {
115 if ($property[0] == '@') {
116 $property = preg_replace_callback('/^(@?)((?:@@)*)([^@]|$)/', function ($matches) use (&$is_source) {
117 // If there are an odd number of @ in the beginning, it's a
119 $is_source = empty($matches[1]);
120 // Remove the possible escaping and do not lose the terminating
122 return str_replace('@@', '@', $matches[2]) . $matches[3];
126 $return[] = $row->getSourceProperty($property);
129 $return[] = $row->getDestinationProperty($property);
137 if (is_string($source)) {
138 $this->multiple = is_array($return[0]);
147 public function multiple() {
148 return $this->multiple;