Commit 186a80cb authored by catch's avatar catch
Browse files

Issue #2350821 by dawehner, webflo, alexpott, vijaycs85: Sort views displays by display name

parent 1cac4b5f
...@@ -285,6 +285,11 @@ public function calculateDependencies() { ...@@ -285,6 +285,11 @@ public function calculateDependencies() {
public function preSave(EntityStorageInterface $storage) { public function preSave(EntityStorageInterface $storage) {
parent::preSave($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. // @todo Check whether isSyncing is needed.
if (!$this->isSyncing()) { if (!$this->isSyncing()) {
$this->addCacheMetadata(); $this->addCacheMetadata();
...@@ -421,13 +426,6 @@ public function mergeDefaultDisplaysOptions() { ...@@ -421,13 +426,6 @@ public function mergeDefaultDisplaysOptions() {
// Add the defaults for the display. // Add the defaults for the display.
$displays[$key] = $options; $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); $this->set('display', $displays);
} }
......
...@@ -97,7 +97,7 @@ protected function loadTests() { ...@@ -97,7 +97,7 @@ protected function loadTests() {
} }
// Check the displays have been loaded correctly from config display data. // 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.'); $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 // Check each ViewDisplay object and confirm that it has the correct key and
......
...@@ -48,6 +48,9 @@ public function testReorderDisplay() { ...@@ -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-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'); $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. // Put the block display in front of the page display.
$edit = array( $edit = array(
'displays[page_1][weight]' => 2, 'displays[page_1][weight]' => 2,
...@@ -61,6 +64,9 @@ public function testReorderDisplay() { ...@@ -61,6 +64,9 @@ public function testReorderDisplay() {
$this->assertEqual($displays['default']['position'], 0, 'Make sure the master display comes first.'); $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['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.'); $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.');
} }
/** /**
......
...@@ -52,8 +52,10 @@ public function buildForm(array $form, FormStateInterface $form_state, $display_ ...@@ -52,8 +52,10 @@ public function buildForm(array $form, FormStateInterface $form_state, $display_
protected function prepareEntity() { protected function prepareEntity() {
// Determine the displays available for editing. // Determine the displays available for editing.
if ($tabs = $this->getDisplayTabs($this->entity)) { if ($tabs = $this->getDisplayTabs($this->entity)) {
// If a display isn't specified, use the first one.
if (empty($this->displayID)) { if (empty($this->displayID)) {
// If a display isn't specified, use the first one after sorting by
// #weight.
uasort($tabs, 'Drupal\Component\Utility\SortArray::sortByWeightProperty');
foreach ($tabs as $id => $tab) { foreach ($tabs as $id => $tab) {
if (!isset($tab['#access']) || $tab['#access']) { if (!isset($tab['#access']) || $tab['#access']) {
$this->displayID = $id; $this->displayID = $id;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment