diff --git a/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php b/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php index 3e3a5c4..6e65758 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php +++ b/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php @@ -216,7 +216,7 @@ public function addDisplay($plugin_id = 'page', $title = NULL, $id = NULL) { 'display_plugin' => $plugin_id, 'id' => $id, 'display_title' => $title, - 'position' => NULL, + 'position' => count($this->display), 'display_options' => array(), ); diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php index 4ccd11d..0041fa4 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php @@ -70,10 +70,29 @@ function testDisplayPlugin() { 'display_plugin' => 'display_test', 'id' => 'display_test_1', 'display_title' => 'Display test', - 'position' => NULL, + 'position' => 1, ); $this->assertEqual($displays['display_test_1'], $options); + // Add another one to ensure that position is counted up. + $view->storage->addDisplay('display_test'); + $displays = $view->storage->get('display'); + $options = array( + 'display_options' => array(), + 'display_plugin' => 'display_test', + 'id' => 'display_test_2', + 'display_title' => 'Display test 2', + 'position' => 2, + ); + $this->assertEqual($displays['display_test_2'], $options); + + // Move the second display before the first one in order to test custom + // sorting. + $displays['display_test_1']['position'] = 2; + $displays['display_test_2']['position'] = 1; + $view->storage->set('display', $displays); + $view->save(); + $view->setDisplay('display_test_1'); $this->assertTrue($view->display_handler instanceof DisplayTestPlugin, 'The correct display handler instance is on the view object.'); @@ -88,8 +107,8 @@ function testDisplayPlugin() { // Change this option and check the title of out output. $view->display_handler->overrideOption('test_option', 'Test option title'); - $view->save(); + $output = $view->preview(); $output = drupal_render($output); @@ -99,6 +118,10 @@ function testDisplayPlugin() { // Test that the display category/summary is in the UI. $this->drupalGet('admin/structure/views/view/test_view/edit/display_test_1'); $this->assertText('Display test settings'); + // Ensure that the order is as expected. + $result = $this->xpath('//ul[@id="views-display-menu-tabs"]/li'); + $this->assertEqual((string) $result[0]->a, 'Display test 2'); + $this->assertEqual((string) $result[1]->a, 'Display test'); $this->clickLink('Test option title'); diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php index daadcb8..bc9c50f 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php @@ -109,6 +109,7 @@ public function getDisplayTabs(ViewUI $view) { foreach ($displays as $id => $display) { $tabs[$id] = array( '#theme' => 'menu_local_task', + '#weight' => $display['position'], '#link' => array( 'title' => $this->getDisplayLabel($view, $id), 'href' => 'admin/structure/views/view/' . $view->id() . '/edit/' . $id,