Array * ( * [language] => en * ... * [domain] => http://example.com * ) * [1] => Array * ( * [language] => fr * ... * [domain] => http://fr.example.com * ) * ... * @endcode * * The destination should be an array of all the domains keyed by their * language code: * * @code * domains: Array * ( * [en] => http://example.com * [fr] => http://fr.example.com * ... * @endcode * * The array_build process plugin would be used like this: * * @code * process: * domains: * plugin: array_build * key: language * value: domain * source: languages * @endcode * * @see \Drupal\migrate\Plugin\MigrateProcessInterface * * @MigrateProcessPlugin( * id = "array_build", * handle_multiples = TRUE * ) */ class ArrayBuild extends ProcessPluginBase { /** * {@inheritdoc} */ 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; } }