function ArrayBuild::transform

Same name in other branches
  1. 9 core/modules/migrate/src/Plugin/migrate/process/ArrayBuild.php \Drupal\migrate\Plugin\migrate\process\ArrayBuild::transform()
  2. 10 core/modules/migrate/src/Plugin/migrate/process/ArrayBuild.php \Drupal\migrate\Plugin\migrate\process\ArrayBuild::transform()
  3. 11.x core/modules/migrate/src/Plugin/migrate/process/ArrayBuild.php \Drupal\migrate\Plugin\migrate\process\ArrayBuild::transform()

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\process

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.