From afb2a7924734e8c54d5213202d8cfdedae165c28 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Mon, 14 Mar 2016 10:53:52 +0000
Subject: [PATCH] Issue #2684575 by chx, benjy, quietone: Get is unable to pick
 up 0

---
 .../src/Plugin/migrate/process/Get.php        |  9 ++++----
 .../tests/src/Unit/process/GetTest.php        | 22 +++++++++++++++++++
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/core/modules/migrate/src/Plugin/migrate/process/Get.php b/core/modules/migrate/src/Plugin/migrate/process/Get.php
index 5b720bc25b46..fab2679afcf0 100644
--- a/core/modules/migrate/src/Plugin/migrate/process/Get.php
+++ b/core/modules/migrate/src/Plugin/migrate/process/Get.php
@@ -35,10 +35,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
     $properties = is_string($source) ? array($source) : $source;
     $return = array();
     foreach ($properties as $property) {
-      if (empty($property)) {
-        $return[] = $value;
-      }
-      else {
+      if ($property || (string) $property === '0') {
         $is_source = TRUE;
         if ($property[0] == '@') {
           $property = preg_replace_callback('/^(@?)((?:@@)*)([^@]|$)/', function ($matches) use (&$is_source) {
@@ -57,7 +54,11 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
           $return[] = $row->getDestinationProperty($property);
         }
       }
+      else {
+        $return[] = $value;
+      }
     }
+
     if (is_string($source)) {
       $this->multiple = is_array($return[0]);
       return $return[0];
diff --git a/core/modules/migrate/tests/src/Unit/process/GetTest.php b/core/modules/migrate/tests/src/Unit/process/GetTest.php
index dc8ea70a850e..bdbb551e5779 100644
--- a/core/modules/migrate/tests/src/Unit/process/GetTest.php
+++ b/core/modules/migrate/tests/src/Unit/process/GetTest.php
@@ -82,6 +82,28 @@ public function testTransformSourceArrayAt() {
     $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
     $this->assertSame($value, array('source_value1', 'source_value2', 'source_value3', 'source_value4'));
   }
+
+  /**
+   * Tests the Get plugin when source has integer values.
+   */
+  public function testIntegerValues() {
+    $this->row->expects($this->exactly(2))
+      ->method('getSourceProperty')
+      ->willReturnOnConsecutiveCalls('val1', 'val2');
+
+    $this->plugin->setSource([0 => 0, 1 => 'test']);
+    $return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
+    $this->assertSame([0 => 'val1', 1 => 'val2'], $return);
+
+    $this->plugin->setSource([FALSE]);
+    $return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
+    $this->assertSame([NULL], $return);
+
+    $this->plugin->setSource([NULL]);
+    $return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
+    $this->assertSame([NULL], $return);
+  }
+
 }
 
 namespace Drupal\migrate\Plugin\migrate\process;
-- 
GitLab