summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxjm2017-11-04 03:10:57 -0500
committerxjm2017-11-04 03:10:57 -0500
commit8b86801fa65a02746ecdb0e18b4139dc2f8f7e04 (patch)
treea782853794b0cd582ec8b436d66a64c77607c195
parentd0e379699193d7eec5381aaaf17bbad07391465a (diff)
Issue #2920394 by tim.plunkett: Field Layout should not alter fields placed into regions it doesn't know about
-rw-r--r--core/modules/field_layout/src/FieldLayoutBuilder.php13
-rw-r--r--core/modules/field_layout/tests/src/Unit/FieldLayoutBuilderTest.php18
2 files changed, 26 insertions, 5 deletions
diff --git a/core/modules/field_layout/src/FieldLayoutBuilder.php b/core/modules/field_layout/src/FieldLayoutBuilder.php
index 8ef5d04..fdbefd5 100644
--- a/core/modules/field_layout/src/FieldLayoutBuilder.php
+++ b/core/modules/field_layout/src/FieldLayoutBuilder.php
@@ -67,12 +67,15 @@ class FieldLayoutBuilder implements ContainerInjectionInterface {
$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 @@ class FieldLayoutBuilder implements ContainerInjectionInterface {
// 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'];
}
}
diff --git a/core/modules/field_layout/tests/src/Unit/FieldLayoutBuilderTest.php b/core/modules/field_layout/tests/src/Unit/FieldLayoutBuilderTest.php
index 8e6bf95..4433298 100644
--- a/core/modules/field_layout/tests/src/Unit/FieldLayoutBuilderTest.php
+++ b/core/modules/field_layout/tests/src/Unit/FieldLayoutBuilderTest.php
@@ -93,6 +93,9 @@ class FieldLayoutBuilderTest extends UnitTestCase {
'test1' => [
'#markup' => 'Test1',
],
+ 'test2' => [
+ '#markup' => 'Test2',
+ ],
'non_configurable_field' => [
'#markup' => 'Non-configurable',
],
@@ -111,6 +114,9 @@ class FieldLayoutBuilderTest extends UnitTestCase {
'test1' => [
'region' => 'right',
],
+ 'test2' => [
+ 'region' => 'unknown_region',
+ ],
'non_configurable_field' => [
'region' => 'left',
],
@@ -120,6 +126,9 @@ class FieldLayoutBuilderTest extends UnitTestCase {
]);
$expected = [
+ 'test2' => [
+ '#markup' => 'Test2',
+ ],
'non_configurable_field' => [
'#markup' => 'Non-configurable',
],
@@ -169,6 +178,9 @@ class FieldLayoutBuilderTest extends UnitTestCase {
'#markup' => 'Test2',
'#group' => 'existing_group',
],
+ 'test3' => [
+ '#markup' => 'Test3',
+ ],
'field_layout' => [
'#markup' => 'Field created through the UI happens to be named "Layout"',
],
@@ -190,6 +202,9 @@ class FieldLayoutBuilderTest extends UnitTestCase {
'test2' => [
'region' => 'left',
],
+ 'test3' => [
+ 'region' => 'unknown_region',
+ ],
'field_layout' => [
'region' => 'right',
],
@@ -207,6 +222,9 @@ class FieldLayoutBuilderTest extends UnitTestCase {
'#markup' => 'Test2',
'#group' => 'existing_group',
],
+ 'test3' => [
+ '#markup' => 'Test3',
+ ],
'field_layout' => [
'#markup' => 'Field created through the UI happens to be named "Layout"',
'#group' => 'right',