Commit 518eff9b authored by webchick's avatar webchick

Issue #2422227 by benjy, chx, dawehner: Add setProcessOfProperty to Migration entity

parent 0a84d315
......@@ -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);
}
/**
......@@ -403,6 +407,31 @@ public function setProcess(array $process) {
return $this;
}
/**
* {@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}
*/
......
......@@ -180,23 +180,64 @@ 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.
*
......
......@@ -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);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment