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 {
/**
* {@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 @@ public function testNodeView() {
$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.
*
......
......@@ -67,7 +67,7 @@ public static function tablePreRender($elements) {
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][''];
......
......@@ -817,12 +817,12 @@ protected function getApplicablePluginOptions(FieldDefinitionInterface $field_de
* @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'];
}
/**
......
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