public function ArrayBuild::transform in Drupal 8
Same name and namespace in other branches
- 9 core/modules/migrate/src/Plugin/migrate/process/ArrayBuild.php \Drupal\migrate\Plugin\migrate\process\ArrayBuild::transform()
- 10 core/modules/migrate/src/Plugin/migrate/process/ArrayBuild.php \Drupal\migrate\Plugin\migrate\process\ArrayBuild::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
1 call to ArrayBuild::transform()
- LanguageDomains::transform in core/
modules/ language/ src/ Plugin/ migrate/ process/ LanguageDomains.php - Performs the associated process.
1 method overrides ArrayBuild::transform()
- LanguageDomains::transform in core/
modules/ language/ src/ Plugin/ migrate/ process/ LanguageDomains.php - Performs the associated process.
File
- core/
modules/ migrate/ src/ Plugin/ migrate/ process/ ArrayBuild.php, line 82
Class
- ArrayBuild
- Builds an array based on the key and value configuration.
Namespace
Drupal\migrate\Plugin\migrate\processCode
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$new_value = [];
foreach ((array) $value as $old_key => $old_value) {
// Checks that $old_value is an array.
if (!is_array($old_value)) {
throw new MigrateException("The input should be an array of arrays");
}
// Checks that the key exists.
if (!array_key_exists($this->configuration['key'], $old_value)) {
throw new MigrateException("The key '" . $this->configuration['key'] . "' does not exist");
}
// Checks that the value exists.
if (!array_key_exists($this->configuration['value'], $old_value)) {
throw new MigrateException("The key '" . $this->configuration['value'] . "' does not exist");
}
$new_value[$old_value[$this->configuration['key']]] = $old_value[$this->configuration['value']];
}
return $new_value;
}