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. 8.9.x 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 198

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_iterable($value)) {
        foreach ($value as $key => $new_value) {
            if (!is_array($new_value)) {
                throw new MigrateException(sprintf("Input array should hold elements of type array, instead element was of type '%s'", gettype($new_value)));
            }
            $new_row = new Row($new_value + $source);
            try {
                $migrate_executable->processRow($new_row, $this->configuration['process']);
            } catch (MigrateSkipRowException $e) {
                continue;
            }
            $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 the key can not
            // be transformed.
            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.