diff --git a/core/modules/views/lib/Drupal/views/Entity/View.php b/core/modules/views/lib/Drupal/views/Entity/View.php index e9f9365dbdd4fd687a8c51a7b69a4e556ef0ce55..a75f9bc682133d3b2b615f8209f863b3344a8c7f 100644 --- a/core/modules/views/lib/Drupal/views/Entity/View.php +++ b/core/modules/views/lib/Drupal/views/Entity/View.php @@ -198,7 +198,7 @@ public function addDisplay($plugin_id = 'page', $title = NULL, $id = NULL) { 'display_plugin' => $plugin_id, 'id' => $id, 'display_title' => $title, - 'position' => count($this->display), + 'position' => $id === 'default' ? 0 : count($this->display), 'provider' => $plugin['provider'], 'display_options' => array(), ); diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php index ba143802fd91025debb8be210ca3dd1627cf7a15..933ad94f044b955baffd547180de9449f93c7ae0 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php @@ -240,6 +240,17 @@ protected function displayMethodTests() { $display = $view->get('display'); $this->assertEqual($display[$id]['display_title'], 'Page 3'); + // Ensure the 'default' display always has position zero, regardless of when + // it was created relative to other displays. + $displays = $view->get('display'); + $displays['default']['deleted'] = TRUE; + $view->set('display', $displays); + $view->set('id', $this->randomName()); + $view->save(); + $view->addDisplay('default', $random_title); + $displays = $view->get('display'); + $this->assertEqual($displays['default']['position'], 0, 'Default displays are always in position zero'); + // Tests Drupal\views\Entity\View::generateDisplayId(). // @todo Sadly this method is not public so it cannot be tested. // $view = $this->controller->create(array());