diff --git a/core/modules/migrate/src/Entity/Migration.php b/core/modules/migrate/src/Entity/Migration.php index ba563f1..3143b62 100644 --- a/core/modules/migrate/src/Entity/Migration.php +++ b/core/modules/migrate/src/Entity/Migration.php @@ -14,6 +14,7 @@ use Drupal\migrate\MigrateSkipRowException; use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Plugin\RequirementsInterface; +use Drupal\Component\Utility\NestedArray; /** * Defines the Migration entity. @@ -77,6 +78,9 @@ class Migration extends ConfigEntityBase implements MigrationInterface, Requirem /** * The configuration describing the process plugins. * + * This is a strictly internal property and should not returned to calling + * code, use getProcess() instead. + * * @var array */ protected $process; @@ -392,7 +396,7 @@ public function isComplete() { * {@inheritdoc} */ public function getProcess() { - return $this->process; + return $this->getProcessNormalized($this->process); } /** @@ -406,6 +410,31 @@ public function setProcess(array $process) { /** * {@inheritdoc} */ + public function setProcessOfProperty($property, $process_of_property) { + $this->process[$property] = $process_of_property; + return $this; + } + + /** + * {@inheritdoc} + */ + public function mergeProcessOfProperty($property, array $process_of_property) { + // If we already have a process value then merge the incoming process array + //otherwise simply set it. + $current_process = $this->getProcess(); + if (isset($current_process[$property])) { + $this->process = NestedArray::mergeDeepArray([$current_process, $this->getProcessNormalized([$property => $process_of_property])], TRUE); + } + else { + $this->setProcessOfProperty($property, $process_of_property); + } + + return $this; + } + + /** + * {@inheritdoc} + */ public function getSystemOfRecord() { return $this->systemOfRecord; } diff --git a/core/modules/migrate/src/Entity/MigrationInterface.php b/core/modules/migrate/src/Entity/MigrationInterface.php index 09cc770..bce1854 100644 --- a/core/modules/migrate/src/Entity/MigrationInterface.php +++ b/core/modules/migrate/src/Entity/MigrationInterface.php @@ -180,24 +180,65 @@ public function setMigrationResult($result); public function getMigrationResult(); /** - * Get the current configuration describing the process plugins. + * Get the normalized process pipeline configuration describing the process + * plugins. + * + * The process configuration is always normalized. All shorthand processing + * will be expanded into their full representations. + * + * @see https://www.drupal.org/node/2129651#get-shorthand * * @return array - * The configuration describing the process plugins. + * The normalized configuration describing the process plugins. */ public function getProcess(); /** - * Set the current configuration describing the process plugins. + * Allows you to override the entire process configuration. * * @param array $process - * The configuration describing the process plugins. + * The entire process pipeline configuration describing the process plugins. * * @return $this */ public function setProcess(array $process); /** + * Set the process pipeline configuration for an individual destination field. + * + * This method allows you to set the process pipeline configuration for a + * single property within the full process pipeline configuration. + * + * @param string $property + * The property of which to set the process pipeline configuration. + * @param mixed $process_of_property + * The process pipeline configuration to be set for this property. + * + * @return $this + * The migration entity. + * + * @see Drupal\migrate_drupal\Plugin\migrate\load\LoadEntity::processLinkField(). + */ + public function setProcessOfProperty($property, $process_of_property); + + /** + * Merge the process pipeline configuration for a single property. + * + * @param string $property + * The property of which to merge the passed in process pipeline + * configuration. + * @param array $process_of_property + * The process pipeline configuration to be merged with the existing process + * pipeline configuration. + * + * @return $this + * The migration entity. + * + * @see Drupal\migrate_drupal\Plugin\migrate\load\LoadEntity::processLinkField(). + */ + public function mergeProcessOfProperty($property, array $process_of_property); + + /** * 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); } }