From 9beae4fe1735281ea34190cd403d44494fb98257 Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Wed, 18 Dec 2013 14:42:29 -0800
Subject: [PATCH] Issue #2154563 by chx:  Migrate process plugin: flatten.

---
 .../Plugin/migrate/process/Flatten.php        | 29 ++++++++++++++
 .../migrate/Tests/process/FlattenTest.php     | 39 +++++++++++++++++++
 2 files changed, 68 insertions(+)
 create mode 100644 core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/process/Flatten.php
 create mode 100644 core/modules/migrate/tests/Drupal/migrate/Tests/process/FlattenTest.php

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 000000000000..22e06ec3c05f
--- /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 000000000000..d1f8c356935f
--- /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));
+  }
+
+}
-- 
GitLab