diff --git a/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php index 361206c..167f169 100644 --- a/core/modules/views/src/Entity/View.php +++ b/core/modules/views/src/Entity/View.php @@ -285,6 +285,11 @@ public function calculateDependencies() { public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); + // Sort the displays. + $display = $this->get('display'); + ksort($display); + $this->set('display', array('default' => $display['default']) + $display); + // @todo Check whether isSyncing is needed. if (!$this->isSyncing()) { $this->addCacheMetadata(); @@ -421,13 +426,6 @@ public function mergeDefaultDisplaysOptions() { // Add the defaults for the display. $displays[$key] = $options; } - // Sort the displays. - uasort($displays, function ($display1, $display2) { - if ($display1['position'] != $display2['position']) { - return $display1['position'] < $display2['position'] ? -1 : 1; - } - return 0; - }); $this->set('display', $displays); } diff --git a/core/modules/views/src/Tests/ViewStorageTest.php b/core/modules/views/src/Tests/ViewStorageTest.php index 3eeda98..19ec50e 100644 --- a/core/modules/views/src/Tests/ViewStorageTest.php +++ b/core/modules/views/src/Tests/ViewStorageTest.php @@ -97,7 +97,7 @@ protected function loadTests() { } // Check the displays have been loaded correctly from config display data. - $expected_displays = array('default', 'page_1', 'block_1'); + $expected_displays = array('default', 'block_1', 'page_1'); $this->assertEqual(array_keys($view->get('display')), $expected_displays, 'The correct display names are present.'); // Check each ViewDisplay object and confirm that it has the correct key and diff --git a/core/modules/views_ui/src/Tests/DisplayTest.php b/core/modules/views_ui/src/Tests/DisplayTest.php index 9fb9866..1188f5d 100644 --- a/core/modules/views_ui/src/Tests/DisplayTest.php +++ b/core/modules/views_ui/src/Tests/DisplayTest.php @@ -48,6 +48,9 @@ public function testReorderDisplay() { $this->assertTrue($this->xpath('//tr[@id="display-row-page_1"]'), 'Make sure the page display appears on the reorder listing'); $this->assertTrue($this->xpath('//tr[@id="display-row-block_1"]'), 'Make sure the block display appears on the reorder listing'); + // Ensure the view displays are in the expected order in configuration. + $expected_display_order = array('default', 'block_1', 'page_1'); + $this->assertEqual(array_keys(Views::getView($view['id'])->storage->get('display')), $expected_display_order, 'The correct display names are present.'); // Put the block display in front of the page display. $edit = array( 'displays[page_1][weight]' => 2, @@ -61,6 +64,9 @@ public function testReorderDisplay() { $this->assertEqual($displays['default']['position'], 0, 'Make sure the master display comes first.'); $this->assertEqual($displays['block_1']['position'], 1, 'Make sure the block display comes before the page display.'); $this->assertEqual($displays['page_1']['position'], 2, 'Make sure the page display comes after the block display.'); + + // Ensure the view displays are in the expected order in configuration. + $this->assertEqual(array_keys($view->storage->get('display')), $expected_display_order, 'The correct display names are present.'); } /**