diff --git a/core/modules/migrate/src/Entity/Migration.php b/core/modules/migrate/src/Entity/Migration.php index ba563f1..46280c1 100644 --- a/core/modules/migrate/src/Entity/Migration.php +++ b/core/modules/migrate/src/Entity/Migration.php @@ -9,11 +9,13 @@ use Drupal\Component\Utility\String; use Drupal\Core\Config\Entity\ConfigEntityBase; +use Drupal\Core\Entity\EntityStorageInterface; use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateSkipRowException; use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Plugin\RequirementsInterface; +use Drupal\Component\Utility\NestedArray; /** * Defines the Migration entity. @@ -406,6 +408,30 @@ public function setProcess(array $process) { /** * {@inheritdoc} */ + public function setProcessOfProperty($field_name, $process) { + $this->process = $this->getProcessNormalized([$field_name => $process]) + $this->process; + return $this; + } + + /** + * {@inheritdoc} + */ + public function mergeProcessOfProperty($field_name, array $process) { + // If we already have a process value then merge the incoming process array + //otherwise simply set it. + if (isset($this->process[$field_name])) { + $this->process = NestedArray::mergeDeepArray([$this->process, $this->getProcessNormalized([$field_name => $process])], TRUE); + } + else { + $this->setProcessOfProperty($field_name, $process); + } + + return $this; + } + + /** + * {@inheritdoc} + */ public function getSystemOfRecord() { return $this->systemOfRecord; } @@ -439,4 +465,16 @@ public function setTrackLastImported($track_last_imported) { public function getMigrationDependencies() { return $this->migration_dependencies; } + + /** + * {@inheritdoc} + */ + public static function postLoad(EntityStorageInterface $storage, array &$entities) { + parent::postLoad($storage, $entities); + /** @var \Drupal\migrate\Entity\Migration $entity */ + foreach ($entities as $entity) { + $entity->setProcess($entity->getProcessNormalized($entity->getProcess())); + } + } + } diff --git a/core/modules/migrate/src/Entity/MigrationInterface.php b/core/modules/migrate/src/Entity/MigrationInterface.php index 09cc770..fc575a2 100644 --- a/core/modules/migrate/src/Entity/MigrationInterface.php +++ b/core/modules/migrate/src/Entity/MigrationInterface.php @@ -198,6 +198,36 @@ public function getProcess(); public function setProcess(array $process); /** + * Set the process for an individual destination field. + * + * @param string $field_name + * The field name of which to set the process. + * @param mixed $process + * A valid process value, array or string. + * + * @return $this + * The migration entity. + * + * @see Drupal\migrate_drupal\Plugin\migrate\load\LoadEntity::processLinkField(). + */ + public function setProcessOfProperty($field_name, $process); + + /** + * Merge the process arrays for an individual field. + * + * @param string $field_name + * The field name of which to set the process. + * @param array $process + * An array of process data. + * + * @return $this + * The migration entity. + * + * @see Drupal\migrate_drupal\Plugin\migrate\load\LoadEntity::processLinkField(). + */ + public function mergeProcessOfProperty($field_name, array $process); + + /** * Get the current system of record of the migration. * * @return string diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php b/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php index c9db0e7..f04672d 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php @@ -98,9 +98,7 @@ public function loadMultiple(EntityStorageInterface $storage, array $sub_ids = N $this->processTextField($field_name, $data, $migration); break; default: - $process = $migration->getProcess(); - $process[$field_name] = $field_name; - $migration->setProcess($process); + $migration->setProcessOfProperty($field_name, $field_name); } } } @@ -134,12 +132,11 @@ protected function processTextField($field_name, $field_data, MigrationInterface $value_key = $field_data['db_storage'] ? $field_name : "$field_name/value"; $format_key = $field_data['db_storage'] ? $field_name . '_format' : "$field_name/format" ; - $process = $migration->getProcess(); + $migration->setProcessOfProperty("$field_name/value", $value_key); - $process["$field_name/value"] = $value_key; // See d6_user, signature_format for an example of the YAML that // represents this process array. - $process["$field_name/format"] = [ + $process = [ [ 'plugin' => 'static_map', 'bypass' => TRUE, @@ -153,8 +150,7 @@ protected function processTextField($field_name, $field_data, MigrationInterface 'source' => $format_key, ], ]; - - $migration->setProcess($process); + $migration->mergeProcessOfProperty("$field_name/format", $process); } /** @@ -168,8 +164,7 @@ protected function processTextField($field_name, $field_data, MigrationInterface * The migration entity. */ protected function processFileField($field_name, $field_data, MigrationInterface $migration) { - $process = $migration->getProcess(); - $process[$field_name] = [ + $process = [ 'plugin' => 'd6_cck_file', 'source' => [ $field_name, @@ -177,7 +172,7 @@ protected function processFileField($field_name, $field_data, MigrationInterface $field_name . '_data', ], ]; - $migration->setProcess($process); + $migration->mergeProcessOfProperty($field_name, $process); } /** @@ -193,8 +188,7 @@ protected function processFileField($field_name, $field_data, MigrationInterface protected function processLinkField($field_name, $field_data, MigrationInterface $migration) { // Specifically process the link field until core is fixed. // @see https://www.drupal.org/node/2235457 - $process = $migration->getProcess(); - $process[$field_name] = [ + $process = [ 'plugin' => 'd6_cck_link', 'source' => [ $field_name, @@ -202,7 +196,7 @@ protected function processLinkField($field_name, $field_data, MigrationInterface $field_name . '_attributes', ], ]; - $migration->setProcess($process); + $migration->mergeProcessOfProperty($field_name, $process); } }