1. 8.5.x core/modules/migrate/src/Plugin/migrate/process/Get.php Get
  2. 8.0.x core/modules/migrate/src/Plugin/migrate/process/Get.php Get
  3. 8.1.x core/modules/migrate/src/Plugin/migrate/process/Get.php Get
  4. 8.2.x core/modules/migrate/src/Plugin/migrate/process/Get.php Get
  5. 8.3.x core/modules/migrate/src/Plugin/migrate/process/Get.php Get
  6. 8.4.x core/modules/migrate/src/Plugin/migrate/process/Get.php Get
  7. 8.6.x core/modules/migrate/src/Plugin/migrate/process/Get.php 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"
)

Hierarchy

Expanded class hierarchy of Get

See also

\Drupal\migrate\Plugin\MigrateProcessInterface

2 files declare their use of Get
IteratorTest.php in core/modules/migrate/tests/src/Unit/process/IteratorTest.php
SubProcessTest.php in core/modules/migrate/tests/src/Unit/process/SubProcessTest.php

File

core/modules/migrate/src/Plugin/migrate/process/Get.php, line 94

Namespace

Drupal\migrate\Plugin\migrate\process
View 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') {
        $is_source = TRUE;
        if ($property[0] == '@') {
          $property = preg_replace_callback('/^(@?)((?:@@)*)([^@]|$)/', function ($matches) use (&$is_source) {

            // If there are an odd number of @ in the beginning, it's a
            // destination.
            $is_source = empty($matches[1]);

            // Remove the possible escaping and do not lose the terminating
            // non-@ either.
            return str_replace('@@', '@', $matches[2]) . $matches[3];
          }, $property);
        }
        if ($is_source) {
          $return[] = $row
            ->getSourceProperty($property);
        }
        else {
          $return[] = $row
            ->getDestinationProperty($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

Contains filters are case sensitive
Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function Prevents serializing any properties.
DependencySerializationTrait::__wakeup public function
Get::$multiple protected property Flag indicating whether there are multiple values.
Get::multiple public function Indicates whether the returned value requires multiple handling. Overrides ProcessPluginBase::multiple
Get::transform public function Performs the associated process. Overrides ProcessPluginBase::transform
PluginBase::$configuration protected property Configuration information passed into the plugin.
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::__construct public function Constructs a Drupal\Component\Plugin\PluginBase object.
StringTranslationTrait::$stringTranslation protected property The string translation service.
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use.
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.