diff core/modules/field_layout/src/FieldLayoutBuilder.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children
line wrap: on
line diff
--- a/core/modules/field_layout/src/FieldLayoutBuilder.php	Fri Feb 23 15:51:18 2018 +0000
+++ b/core/modules/field_layout/src/FieldLayoutBuilder.php	Fri Feb 23 15:52:07 2018 +0000
@@ -67,12 +67,15 @@
       $regions = array_fill_keys($layout_definition->getRegionNames(), []);
 
       foreach ($fields as $name => $field) {
-        // Move the field from the top-level of $build into a region-specific
-        // section.
+        // If the region is controlled by the layout, move the field from the
+        // top-level of $build into a region-specific section. Custom regions
+        // could be set by other code at run-time; these should be ignored.
         // @todo Ideally the array structure would remain unchanged, see
         //   https://www.drupal.org/node/2846393.
-        $regions[$field['region']][$name] = $build[$name];
-        unset($build[$name]);
+        if (isset($regions[$field['region']])) {
+          $regions[$field['region']][$name] = $build[$name];
+          unset($build[$name]);
+        }
       }
       // Ensure this will not conflict with any existing array elements by
       // prefixing with an underscore.
@@ -103,7 +106,7 @@
         // avoids breaking hook_form_alter() implementations by not actually
         // moving the field in the form structure. If a #group is already set,
         // do not overwrite it.
-        if (!isset($build[$name]['#group'])) {
+        if (isset($regions[$field['region']]) && !isset($build[$name]['#group'])) {
           $build[$name]['#group'] = $field['region'];
         }
       }