From 992ed45b26cd520dbd79c720ba44789191d0c630 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Sat, 29 Apr 2017 21:07:40 +0100 Subject: [PATCH] Issue #2870410 by tim.plunkett: Field UI should show fields with unknown regions in the "Disabled" section --- .../field_layout_test/field_layout_test.module | 16 ++++++++++++++++ .../tests/src/Functional/FieldLayoutTest.php | 18 +++++++++++++++++- .../field_ui/src/Element/FieldUiTable.php | 2 +- .../src/Form/EntityDisplayFormBase.php | 10 +++++----- 4 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 core/modules/field_layout/tests/modules/field_layout_test/field_layout_test.module diff --git a/core/modules/field_layout/tests/modules/field_layout_test/field_layout_test.module b/core/modules/field_layout/tests/modules/field_layout_test/field_layout_test.module new file mode 100644 index 000000000000..6905c3daac15 --- /dev/null +++ b/core/modules/field_layout/tests/modules/field_layout_test/field_layout_test.module @@ -0,0 +1,16 @@ +get('field_layout_test.alter_regions') && isset($definitions['layout_onecol'])) { + $definitions['layout_onecol']->setRegions(['foo' => ['label' => 'Foo']]); + } +} diff --git a/core/modules/field_layout/tests/src/Functional/FieldLayoutTest.php b/core/modules/field_layout/tests/src/Functional/FieldLayoutTest.php index 683ccd2f93f1..a12ae18ac059 100644 --- a/core/modules/field_layout/tests/src/Functional/FieldLayoutTest.php +++ b/core/modules/field_layout/tests/src/Functional/FieldLayoutTest.php @@ -14,7 +14,7 @@ class FieldLayoutTest extends BrowserTestBase { /** * {@inheritdoc} */ - public static $modules = ['field_layout', 'field_ui', 'node']; + public static $modules = ['field_layout', 'field_ui', 'node', 'field_layout_test']; /** * {@inheritdoc} @@ -57,6 +57,22 @@ class FieldLayoutTest extends BrowserTestBase { $this->assertSession()->optionExists('fields[body][region]', 'content'); } + /** + * Tests that changes to the regions still leave the fields visible. + */ + public function testRegionChanges() { + $this->drupalGet('admin/structure/types/manage/article/display'); + $this->assertEquals(['Content', 'Disabled'], $this->getRegionTitles()); + $this->assertSession()->optionExists('fields[body][region]', 'content'); + + \Drupal::state()->set('field_layout_test.alter_regions', TRUE); + \Drupal::service('plugin.cache_clearer')->clearCachedDefinitions(); + + $this->drupalGet('admin/structure/types/manage/article/display'); + $this->assertEquals(['Foo', 'Disabled'], $this->getRegionTitles()); + $this->assertSession()->optionExists('fields[body][region]', 'hidden'); + } + /** * Gets the region titles on the page. * diff --git a/core/modules/field_ui/src/Element/FieldUiTable.php b/core/modules/field_ui/src/Element/FieldUiTable.php index f8f3146759ea..84cafb089368 100644 --- a/core/modules/field_ui/src/Element/FieldUiTable.php +++ b/core/modules/field_ui/src/Element/FieldUiTable.php @@ -67,7 +67,7 @@ class FieldUiTable extends Table { unset($list[$name]); // Determine the region for the row. - $region_name = call_user_func($row['#region_callback'], $row); + $region_name = call_user_func_array($row['#region_callback'], [&$row]); // Add the element in the tree. $target = &$trees[$region_name]['']; diff --git a/core/modules/field_ui/src/Form/EntityDisplayFormBase.php b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php index 62a46b1c1406..0a91862b351e 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayFormBase.php +++ b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php @@ -817,12 +817,12 @@ abstract class EntityDisplayFormBase extends EntityForm { * @return string|null * The region name this row belongs to. */ - public function getRowRegion($row) { - switch ($row['#row_type']) { - case 'field': - case 'extra_field': - return $row['region']['#value'] ?: 'hidden'; + public function getRowRegion(&$row) { + $regions = $this->getRegions(); + if (!isset($regions[$row['region']['#value']])) { + $row['region']['#value'] = 'hidden'; } + return $row['region']['#value']; } /**