diff --git a/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/process/Flatten.php b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/process/Flatten.php new file mode 100644 index 0000000000000000000000000000000000000000..22e06ec3c05f684386bd24b5f600c4b61b3bb135 --- /dev/null +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/process/Flatten.php @@ -0,0 +1,29 @@ +<?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 { + + /** diff --git a/core/modules/migrate/tests/Drupal/migrate/Tests/process/FlattenTest.php b/core/modules/migrate/tests/Drupal/migrate/Tests/process/FlattenTest.php new file mode 100644 index 0000000000000000000000000000000000000000..d1f8c356935f3f36c4c611fbbe65a124656d4b9c --- /dev/null +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/process/FlattenTest.php @@ -0,0 +1,39 @@ +<?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)); + } + +}