From 1ce074c499c89b13afd8b9c0ffae73f78d271308 Mon Sep 17 00:00:00 2001
From: webchick <drupal@webchick.net>
Date: Thu, 3 Sep 2015 10:54:49 -0700
Subject: [PATCH] Issue #2562089 by phenaproxima: d7_field_formatter_settings
 migration does not handle empty settings

---
 .../d7_field_formatter_settings.yml           |  5 +-
 .../d7/MigrateFieldFormatterSettingsTest.php  | 58 +++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/core/modules/field/migration_templates/d7_field_formatter_settings.yml b/core/modules/field/migration_templates/d7_field_formatter_settings.yml
index 1171ec359834..7ee6fe2ce5f2 100644
--- a/core/modules/field/migration_templates/d7_field_formatter_settings.yml
+++ b/core/modules/field/migration_templates/d7_field_formatter_settings.yml
@@ -62,7 +62,10 @@ process:
     -
       plugin: skip_on_empty
       method: row
-  "options/settings": settings
+  "options/settings":
+    plugin: default_value
+    source: settings
+    default_value: []
   "options/third_party_settings": 'constants/third_party_settings'
 destination:
   plugin: component_entity_display
diff --git a/core/modules/field/src/Tests/Migrate/d7/MigrateFieldFormatterSettingsTest.php b/core/modules/field/src/Tests/Migrate/d7/MigrateFieldFormatterSettingsTest.php
index 74c0e175520f..569c23782f68 100644
--- a/core/modules/field/src/Tests/Migrate/d7/MigrateFieldFormatterSettingsTest.php
+++ b/core/modules/field/src/Tests/Migrate/d7/MigrateFieldFormatterSettingsTest.php
@@ -8,6 +8,7 @@
 namespace Drupal\field\Tests\Migrate\d7;
 
 use Drupal\comment\Entity\CommentType;
+use Drupal\Core\Database\Database;
 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
 use Drupal\Core\Entity\Entity\EntityViewDisplay;
 use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
@@ -89,6 +90,63 @@ protected function setUp() {
       'label' => $this->randomMachineName(),
     ])->save();
 
+    // Give one unfortunate field instance invalid display settings to ensure
+    // that the migration provides an empty array as a default (thus avoiding
+    // an "unsupported operand types" fatal).
+    Database::getConnection('default', 'migrate')
+      ->update('field_config_instance')
+      ->fields(array(
+        'data' => serialize(array (
+          'label' => 'Body',
+          'widget' =>
+            array (
+              'type' => 'text_textarea_with_summary',
+              'settings' =>
+                array (
+                  'rows' => 20,
+                  'summary_rows' => 5,
+                ),
+              'weight' => -4,
+              'module' => 'text',
+            ),
+          'settings' =>
+            array (
+              'display_summary' => true,
+              'text_processing' => 1,
+              'user_register_form' => false,
+            ),
+          'display' =>
+            array (
+              'default' =>
+                array (
+                  'label' => 'hidden',
+                  'type' => 'text_default',
+                  'settings' =>
+                    array (
+                    ),
+                  'module' => 'text',
+                  'weight' => 0,
+                ),
+              'teaser' =>
+                array (
+                  'label' => 'hidden',
+                  'type' => 'text_summary_or_trimmed',
+                  // settings is always expected to be an array. Making it NULL
+                  // causes a fatal.
+                  'settings' => NULL,
+                  'module' => 'text',
+                  'weight' => 0,
+                ),
+            ),
+          'required' => false,
+          'description' => '',
+        )),
+      ))
+      ->condition('entity_type', 'node')
+      ->condition('bundle', 'article')
+      ->condition('field_name', 'body')
+      ->execute();
+
     $this->executeMigration('d7_field');
     $this->executeMigration('d7_field_instance');
     $this->executeMigration('d7_view_modes');
-- 
GitLab