Commit 186a80cb authored by catch's avatar catch

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

parent 1cac4b5f
......@@ -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);
}
......
......@@ -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
......
......@@ -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.');
}
/**
......
......@@ -52,8 +52,10 @@ public function buildForm(array $form, FormStateInterface $form_state, $display_
protected function prepareEntity() {
// Determine the displays available for editing.
if ($tabs = $this->getDisplayTabs($this->entity)) {
// If a display isn't specified, use the first one.
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) {
if (!isset($tab['#access']) || $tab['#access']) {
$this->displayID = $id;
......
Markdown is supported
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