Skip to content
Snippets Groups Projects
Commit 9beae4fe authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2154563 by chx: Migrate process plugin: flatten.

parent 7080c759
No related branches found
No related tags found
No related merge requests found
<?php
/**
* @file
* Contains \Drupal\migrate\Plugin\migrate\process\Flatten.
*/
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* This plugin flattens the current value.
*
* During some types of processing (e.g. user permission splitting), what was
* once a single value gets transformed into multiple values. This plugin will
* flatten them back down to single values again.
*
* @see https://drupal.org/node/2154215
*
* @MigrateProcessPlugin(
* id = "flatten",
* handle_multiples = TRUE
* )
*/
class Flatten extends ProcessPluginBase {
/**
<?php
/**
* @file
* Contains \Drupal\migrate\Tests\process\FlattenTest.
*/
namespace Drupal\migrate\Tests\process;
use Drupal\migrate\Plugin\migrate\process\Flatten;
/**
* Tests the flatten plugin.
*
* @group Drupal
* @group migrate
*/
class FlattenTest extends MigrateProcessTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Flatten process plugin',
'description' => 'Tests the flatten process plugin.',
'group' => 'Migrate',
);
}
/**
* Test that various array flatten operations work properly.
*/
public function testFlatten() {
$plugin = new Flatten(array(), 'flatten', array());
$flattened = $plugin->transform(array(1, 2, array(3, 4, array(5)), array(), array(7, 8)), $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame($flattened, array(1, 2, 3, 4, 5, 7, 8));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment