You are here

public function SubProcess::transform in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/migrate/src/Plugin/migrate/process/SubProcess.php \Drupal\migrate\Plugin\migrate\process\SubProcess::transform()

Performs the associated process.

Parameters

mixed $value: The value to be transformed.

\Drupal\migrate\MigrateExecutableInterface $migrate_executable: The migration in which this process is being executed.

\Drupal\migrate\Row $row: The row from the source to process. Normally, just transforming the value is adequate but very rarely you might need to change two columns at the same time or something like that.

string $destination_property: The destination property currently worked on. This is only used together with the $row above.

Return value

string|array The newly transformed value.

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;
}