Issue #2896215 by tim.plunkett, borisson_, Anybody, tacituseu: Formatter settings lost when moving fields between regions in 'Manage display'

8.7.x
Lee Rowlands 2018-10-26 06:59:16 +10:00
parent a007373c93
commit 1f03271798
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
3 changed files with 50 additions and 12 deletions

View File

@ -239,6 +239,40 @@ class FieldLayoutTest extends WebDriverTestBase {
$this->assertSession()->pageTextContains('Blah: Test text');
}
/**
* Tests changing the formatter and region at the same time.
*/
public function testChangingFormatterAndRegion() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
// Add the test field to the content region.
$this->drupalGet('entity_test/structure/entity_test/display');
$page->find('css', '#field-test-text .handle')->dragTo($page->find('css', '.region-content-message'));
$assert_session->assertWaitOnAjaxRequest();
$page->pressButton('Save');
$assert_session->fieldValueEquals('fields[field_test_text][region]', 'content');
$assert_session->fieldValueEquals('fields[field_test_text][type]', 'text_default');
// Switch the layout to two columns.
$this->click('#edit-field-layouts');
$page->selectFieldOption('field_layout', 'layout_twocol');
$assert_session->assertWaitOnAjaxRequest();
$page->pressButton('Save');
$assert_session->fieldValueEquals('fields[field_test_text][region]', 'first');
// Change the formatter and move to another region.
$page->selectFieldOption('fields[field_test_text][type]', 'text_trimmed');
$assert_session->assertWaitOnAjaxRequest();
$page->find('css', '#field-test-text .handle')->dragTo($page->find('css', '.region-second-message'));
$assert_session->assertWaitOnAjaxRequest();
$page->pressButton('Save');
// Assert that both the formatter and region change are persisted.
$assert_session->fieldValueEquals('fields[field_test_text][region]', 'second');
$assert_session->fieldValueEquals('fields[field_test_text][type]', 'text_trimmed');
}
/**
* Gets the region titles on the page.
*

View File

@ -343,16 +343,18 @@
// Set the region of the select list.
this.$regionSelect.val(region);
// Restore the formatter back to the default formatter. Pseudo-fields
// do not have default formatters, we just return to 'visible' for
// those.
const value =
typeof this.defaultPlugin !== 'undefined'
? this.defaultPlugin
: this.$pluginSelect.find('option').val();
// Restore the formatter back to the default formatter only if it was
// disabled previously. Pseudo-fields do not have default formatters,
// we just return to 'visible' for those.
if (this.region === 'hidden') {
const value =
typeof this.defaultPlugin !== 'undefined'
? this.defaultPlugin
: this.$pluginSelect.find('option').val();
if (typeof value !== 'undefined') {
this.$pluginSelect.val(value);
if (typeof value !== 'undefined') {
this.$pluginSelect.val(value);
}
}
const refreshRows = {};

View File

@ -163,10 +163,12 @@
this.$regionSelect.val(region);
var value = typeof this.defaultPlugin !== 'undefined' ? this.defaultPlugin : this.$pluginSelect.find('option').val();
if (this.region === 'hidden') {
var value = typeof this.defaultPlugin !== 'undefined' ? this.defaultPlugin : this.$pluginSelect.find('option').val();
if (typeof value !== 'undefined') {
this.$pluginSelect.val(value);
if (typeof value !== 'undefined') {
this.$pluginSelect.val(value);
}
}
var refreshRows = {};