diff --git a/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php index ea3664e..0d4b585 100644 --- a/core/modules/views/src/Entity/View.php +++ b/core/modules/views/src/Entity/View.php @@ -298,6 +298,18 @@ public function calculateDependencies() { /** * {@inheritdoc} */ + 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); + } + + /** + * {@inheritdoc} + */ public function postSave(EntityStorageInterface $storage, $update = TRUE) { parent::postSave($storage, $update); @@ -390,13 +402,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 7a05428..07569a3 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/DisplayCRUDTest.php b/core/modules/views_ui/src/Tests/DisplayCRUDTest.php index fecf451..94a2d09 100644 --- a/core/modules/views_ui/src/Tests/DisplayCRUDTest.php +++ b/core/modules/views_ui/src/Tests/DisplayCRUDTest.php @@ -98,8 +98,8 @@ public function testRemoveDisplay() { */ public function testDefaultDisplay() { $this->drupalGet('admin/structure/views/view/test_display'); - $elements = $this->xpath('//*[@id="views-page-1-display-title"]'); - $this->assertEqual(count($elements), 1, 'The page display is loaded as the default display.'); + $elements = $this->xpath('//*[@id="views-block-1-display-title"]'); + $this->assertEqual(count($elements), 1, 'The block display is loaded as the default display.'); } /** diff --git a/core/modules/views_ui/src/ViewFormBase.php b/core/modules/views_ui/src/ViewFormBase.php index 9544040..55f4ef7 100644 --- a/core/modules/views_ui/src/ViewFormBase.php +++ b/core/modules/views_ui/src/ViewFormBase.php @@ -47,6 +47,21 @@ protected function prepareEntity() { if ($tabs = $this->getDisplayTabs($this->entity)) { // If a display isn't specified, use the first one. if (empty($this->displayID)) { + + uksort($tabs, function($a, $b) { + // Prioritize: default, page, block, other ones. + if (strpos($a, 'default') === 0 || strpos($b, 'default') === 0) { + return -1; + } + if (strpos($a, 'page') === 0 || strpos($b, 'page') === 0) { + return -1; + } + if (strpos($a, 'block') === 0 || strpos($b, 'block') === 0) { + return -1; + } + return $a < $b ? -1 : 1; + }); + foreach ($tabs as $id => $tab) { if (!isset($tab['#access']) || $tab['#access']) { $this->displayID = $id;