Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
186a80cb
Commit
186a80cb
authored
Nov 21, 2014
by
catch
Browse files
Issue
#2350821
by dawehner, webflo, alexpott, vijaycs85: Sort views displays by display name
parent
1cac4b5f
Changes
4
Hide whitespace changes
Inline
Side-by-side
core/modules/views/src/Entity/View.php
View file @
186a80cb
...
...
@@ -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
);
}
...
...
core/modules/views/src/Tests/ViewStorageTest.php
View file @
186a80cb
...
...
@@ -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
...
...
core/modules/views_ui/src/Tests/DisplayTest.php
View file @
186a80cb
...
...
@@ -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.'
);
}
/**
...
...
core/modules/views_ui/src/ViewFormBase.php
View file @
186a80cb
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment