Skip to content
Snippets Groups Projects
Verified Commit 27229b5a authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #2896215 by tim.plunkett, borisson_, Anybody, tacituseu: Formatter...

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

(cherry picked from commit 1f032717)
parent 94b04729
No related branches found
No related tags found
No related merge requests found
...@@ -239,6 +239,40 @@ public function testLayoutForms() { ...@@ -239,6 +239,40 @@ public function testLayoutForms() {
$this->assertSession()->pageTextContains('Blah: Test text'); $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. * Gets the region titles on the page.
* *
......
...@@ -343,16 +343,18 @@ ...@@ -343,16 +343,18 @@
// Set the region of the select list. // Set the region of the select list.
this.$regionSelect.val(region); this.$regionSelect.val(region);
// Restore the formatter back to the default formatter. Pseudo-fields // Restore the formatter back to the default formatter only if it was
// do not have default formatters, we just return to 'visible' for // disabled previously. Pseudo-fields do not have default formatters,
// those. // we just return to 'visible' for those.
const value = if (this.region === 'hidden') {
typeof this.defaultPlugin !== 'undefined' const value =
? this.defaultPlugin typeof this.defaultPlugin !== 'undefined'
: this.$pluginSelect.find('option').val(); ? 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 = {}; const refreshRows = {};
......
...@@ -163,10 +163,12 @@ ...@@ -163,10 +163,12 @@
this.$regionSelect.val(region); 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') { if (typeof value !== 'undefined') {
this.$pluginSelect.val(value); this.$pluginSelect.val(value);
}
} }
var refreshRows = {}; var refreshRows = {};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment