function SubProcess::transform

Same name in other branches
  1. 9 core/modules/migrate/src/Plugin/migrate/process/SubProcess.php \Drupal\migrate\Plugin\migrate\process\SubProcess::transform()
  2. 10 core/modules/migrate/src/Plugin/migrate/process/SubProcess.php \Drupal\migrate\Plugin\migrate\process\SubProcess::transform()
  3. 11.x core/modules/migrate/src/Plugin/migrate/process/SubProcess.php \Drupal\migrate\Plugin\migrate\process\SubProcess::transform()

Overrides ProcessPluginBase::transform

File

core/modules/migrate/src/Plugin/migrate/process/SubProcess.php, line 196

Class

SubProcess
Runs an array of arrays through its own process pipeline.

Namespace

Drupal\migrate\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    $return = $source = [];
    if ($this->configuration['include_source']) {
        $key = $this->configuration['source_key'];
        $source[$key] = $row->getSource();
    }
    if (is_array($value) || $value instanceof \Traversable) {
        foreach ($value as $key => $new_value) {
            $new_row = new Row($new_value + $source);
            $migrate_executable->processRow($new_row, $this->configuration['process']);
            $destination = $new_row->getDestination();
            if (array_key_exists('key', $this->configuration)) {
                $key = $this->transformKey($key, $migrate_executable, $new_row);
            }
            // Do not save the result if the key is NULL. The configured process
            // pipeline used in transformKey() will return NULL if a
            // MigrateSkipProcessException is thrown.
            // @see \Drupal\filter\Plugin\migrate\process\FilterID
            if ($key !== NULL) {
                $return[$key] = $destination;
            }
        }
    }
    return $return;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.