Commit 992ed45b authored by alexpott's avatar alexpott

Issue #2870410 by tim.plunkett: Field UI should show fields with unknown...

Issue #2870410 by tim.plunkett: Field UI should show fields with unknown regions in the "Disabled" section
parent 4971d776
<?php
/**
* @file
* Contains hook implementations for field_layout_test.
*/
/**
* Implements hook_layout_alter().
*/
function field_layout_test_layout_alter(&$definitions) {
/** @var \Drupal\Core\Layout\LayoutDefinition[] $definitions */
if (\Drupal::state()->get('field_layout_test.alter_regions') && isset($definitions['layout_onecol'])) {
$definitions['layout_onecol']->setRegions(['foo' => ['label' => 'Foo']]);
}
}
...@@ -14,7 +14,7 @@ class FieldLayoutTest extends BrowserTestBase { ...@@ -14,7 +14,7 @@ class FieldLayoutTest extends BrowserTestBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static $modules = ['field_layout', 'field_ui', 'node']; public static $modules = ['field_layout', 'field_ui', 'node', 'field_layout_test'];
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -57,6 +57,22 @@ public function testNodeView() { ...@@ -57,6 +57,22 @@ public function testNodeView() {
$this->assertSession()->optionExists('fields[body][region]', 'content'); $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. * Gets the region titles on the page.
* *
......
...@@ -67,7 +67,7 @@ public static function tablePreRender($elements) { ...@@ -67,7 +67,7 @@ public static function tablePreRender($elements) {
unset($list[$name]); unset($list[$name]);
// Determine the region for the row. // 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. // Add the element in the tree.
$target = &$trees[$region_name]['']; $target = &$trees[$region_name][''];
......
...@@ -817,12 +817,12 @@ protected function getApplicablePluginOptions(FieldDefinitionInterface $field_de ...@@ -817,12 +817,12 @@ protected function getApplicablePluginOptions(FieldDefinitionInterface $field_de
* @return string|null * @return string|null
* The region name this row belongs to. * The region name this row belongs to.
*/ */
public function getRowRegion($row) { public function getRowRegion(&$row) {
switch ($row['#row_type']) { $regions = $this->getRegions();
case 'field': if (!isset($regions[$row['region']['#value']])) {
case 'extra_field': $row['region']['#value'] = 'hidden';
return $row['region']['#value'] ?: 'hidden';
} }
return $row['region']['#value'];
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment