Problem/Motivation
When a view uses multiple attachments to be displayed in the same location (e.g. all "above" or all "below"), they are added in order of their machine names, rather than the order specified in the view.
This behavior is not obvious to the user, and changing a display's machine names likely leads to unsemantic naming. If done at a later point, this can furthermore lead to problems because of the old machine name being used in code etc.
Steps to reproduce as an example:
- Create a "pets" view with a
page
and twoattachment
displays, "cats" and "dogs", both set to output "after" the page. - Click on "Reorder displays" and sort them as "page_1", "dogs", "cats".
- On the pets page, the cats will be output before the dogs even though configured differently.
Proposed resolution
Since displays can be rearranged by the user, the attachments should adhere to this order.
Remaining tasks
Write a test for this scenario, review the patch.
Comment | File | Size | Author |
---|---|---|---|
#36 | 2943293-36.patch | 16.93 KB | ameymudras |
#34 | views_machine_name.png | 246.05 KB | rex.barkdoll |
#32 | interdiff_27_32.txt | 9.32 KB | Rassoni |
#32 | 2943293-32.patch | 18.21 KB | Rassoni |
#31 | 2943293-31.patch | 1 byte | gayatri chahar |
Comments
Comment #2
ckaotikI've attached a patch, please review.
Comment #4
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedThis worked for me
Comment #5
zahord CreditAttribution: zahord as a volunteer and at Skilld commentedHi all, checking the patch #5, the test is failing for the Drupal\Tests\views\Functional\Plugin\DisplayTest because two attachments contains the same position, and when you add this $attached_displays[$display['position']] = $display_id;, a view display id is removed.
in the current patch, the approach is to sort first the view displays regarding the position before to get the attached_displays array.
Comment #6
zahord CreditAttribution: zahord as a volunteer and at Skilld commentedComment #7
joachim CreditAttribution: joachim commentedReads a bit funny.
How about:
"Sort the displays by their position."
Should use SortArray::sortByKeyString() here.
Comment #8
Vidushi Mehta CreditAttribution: Vidushi Mehta at gai Technologies Pvt Ltd commentedPatch added.
Comment #9
Vidushi Mehta CreditAttribution: Vidushi Mehta at gai Technologies Pvt Ltd commentedComment #10
Vidushi Mehta CreditAttribution: Vidushi Mehta at gai Technologies Pvt Ltd commentedComment #12
joachim CreditAttribution: joachim commentedMissing space after the //
That's not how this method is used. It's a callback for uasort().
Comment #13
eli-on-drupal CreditAttribution: eli-on-drupal at Mindgrub Technologies commentedHere's a corrected patch.
Comment #14
joachim CreditAttribution: joachim commentedLGTM!
Comment #15
catchPatch itself looks OK, but this needs a test.
Comment #17
bobbygryzyngerAdds a test for the work done in #13.
Comment #19
bobbygryzyngerIn order to not break the alphabetical render ordering of existing display attachments, we need an update hook to rewrite positional ordering in alphabetical order.
Comment #25
ranjith_kumar_k_u CreditAttribution: ranjith_kumar_k_u at Zyxware Technologies commentedRe-rolled #17 for 9.4.
Comment #27
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedFixing failed tests of patch #25.
Comment #29
MatroskeenRe #19:
Let's discuss this by looking at the following example:
1) Display "Block";
2) Display "Attachment 1";
3) Display "Attachment 2";
both attachments were added to "Block".
Sites without this patch will always display attachments in the following order: 2) and 3) ignoring their position.
Sites with this patch will consider the position, so it can be either 2), 3) or 3), 2) depending on the configuration.
The proposed update hook will change the positions and preserve the behavior for sites without the applied patch.
But if the patch is already applied and the position was changed, there is no way to know that, right?
Perhaps the change record will be enough in this case?
Comment #30
Lendude@Matroskeen we can't really take sites that already use this patch into consideration here when writing the update. For this issue that MIGHT still be doable, but for larger and longer running issues we just need to let that go. People that have applied patches need to be aware that things can shift.
So we only consider sites that are unaware of this bug when doing the update.
Comment #31
gayatri chahar CreditAttribution: gayatri chahar as a volunteer and at Srijan | A Material+ Company for Drupal Association commentedFixed for 9.5.x-dev
Comment #32
RassoniRerolled patch
Comment #33
MatroskeenAs per comments #19, #29, and #30, we need an update hook to take care of existing views. Back to Needs Work for that.
Comment #34
rex.barkdoll CreditAttribution: rex.barkdoll commentedUntil we get this fixed properly, using the ReOrder Displays option. I've got a hack - If you go under Advanced in the view and change the Machine Name to be in Alphabetical order for how you want, It will reorder the view's attachments on the front end.
ie:
Let's say your parent view's machine name is "daily" and your attachments' machine names are "attachment_1" and "attachment_2". You want the order to be: daily, attachment_2, attachment1. So now you rename the attachments' machine names: "attachment_2" becomes "daily_1" and "attachment_1" becomes "daily_2"
Save the view and you should see everything in the order you want.
Full credit to Ruc Van over here: https://drupal.stackexchange.com/questions/242274/how-can-i-order-views-...
for figuring this out.
Comment #35
drase15 CreditAttribution: drase15 commentedHaving same problem and also same solution as #31
You can use numbers to set your order, but if you don't like to use "standard" names on your attachments, you can use text instead and drupal view will order alphabetical
Comment #36
ameymudras CreditAttribution: ameymudras at Salsa Digital commentedRe-rolling patch #32 to 10.0.x, I haven't fixed the issues mentioned in #19, #29, and #30 to write an update update hook. Will work on it once I have some time. Not changing the issue status for the same reason