You are here

public function MigrateExecutable::processRow in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/migrate/src/MigrateExecutable.php \Drupal\migrate\MigrateExecutable::processRow()

Processes a row.

Parameters

\Drupal\migrate\Row $row: The $row to be processed.

array $process: (optional) A process pipeline configuration. If not set, the top level process configuration in the migration entity is used.

mixed $value: (optional) Initial value of the pipeline for the first destination. Usually setting this is not necessary as $process typically starts with a 'get'. This is useful only when the $process contains a single destination and needs to access a value outside of the source. See \Drupal\migrate\Plugin\migrate\process\SubProcess::transformKey for an example.

Throws

\Drupal\migrate\MigrateException

Overrides MigrateExecutableInterface::processRow

1 call to MigrateExecutable::processRow()
MigrateExecutable::import in core/modules/migrate/src/MigrateExecutable.php
Performs an import operation - migrate items from source to destination.

File

core/modules/migrate/src/MigrateExecutable.php, line 369

Class

MigrateExecutable
Defines a migrate executable class.

Namespace

Drupal\migrate

Code

public function processRow(Row $row, array $process = NULL, $value = NULL) {
  foreach ($this->migration
    ->getProcessPlugins($process) as $destination => $plugins) {
    $multiple = FALSE;

    /** @var $plugin \Drupal\migrate\Plugin\MigrateProcessInterface */
    foreach ($plugins as $plugin) {
      $definition = $plugin
        ->getPluginDefinition();

      // Many plugins expect a scalar value but the current value of the
      // pipeline might be multiple scalars (this is set by the previous
      // plugin) and in this case the current value needs to be iterated
      // and each scalar separately transformed.
      if ($multiple && !$definition['handle_multiples']) {
        $new_value = [];
        if (!is_array($value)) {
          throw new MigrateException(sprintf('Pipeline failed at %s plugin for destination %s: %s received instead of an array,', $plugin
            ->getPluginId(), $destination, $value));
        }
        $break = FALSE;
        foreach ($value as $scalar_value) {
          try {
            $new_value[] = $plugin
              ->transform($scalar_value, $this, $row, $destination);
          } catch (MigrateSkipProcessException $e) {
            $new_value[] = NULL;
            $break = TRUE;
          }
        }
        $value = $new_value;
        if ($break) {
          break;
        }
      }
      else {
        try {
          $value = $plugin
            ->transform($value, $this, $row, $destination);
        } catch (MigrateSkipProcessException $e) {
          $value = NULL;
          break;
        }
        $multiple = $plugin
          ->multiple();
      }
    }

    // Ensure all values, including nulls, are migrated.
    if ($plugins) {
      if (isset($value)) {
        $row
          ->setDestinationProperty($destination, $value);
      }
      else {
        $row
          ->setEmptyDestinationProperty($destination);
      }
    }

    // Reset the value.
    $value = NULL;
  }
}