Commit cd45ee43 authored by benjifisher's avatar benjifisher Committed by Lucas Hedding
Browse files

Issue #244: Add a process plugin to swap rows, columns

parent 2bbc8b4d
<?php
namespace Drupal\migrate_plus\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Drupal\migrate\ProcessPluginBase;
/**
* Exchange rows and columns.
*
* Example:
*
* @code
* process:
* bar:
* -
* plugin: transpose
* source:
* - foo0
* - foo1
* - foo2
* @endcode
*
* This will create an array of 3-element, numerically indexed arrays. Each
* array will have one element from each of the source properties.
*
* @MigrateProcessPlugin(
* id = "transpose"
* )
*/
class Transpose extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($table, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// Make sure that $table is an array of arrays.
if (!is_array($table)) {
return [];
}
foreach ($table as &$value) {
$value = (array) $value;
}
// @see https://stackoverflow.com/a/47718734/3130080
return array_map(NULL, ...$table);
}
}
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