Problem/Motivation
If you have a nested view-within-a-view, with the Masonry style applied to the container View. The nested view will then also get Masonry applied to it, regardless of what Views style is selected for it.
Reproduction steps
- Enable Masonry Views module
- Create a view listing all published content teaser. Use masonry style. Make sure this view is working OK.
- Enable module FieldView
- Add a fieldview to a content type and display it in the teaser
- Create a second view listing 5 published content
- Set one of your content appearing in the main view to use this second view in the teaser field
1: You will get the listing of nodes within the teaser being "masonry-processed" without the patch.
2: You should get the listing of nodes NOT being processed after patch.
Reviewing process
- Follow reproduction steps and make sure the error is happening
- Apply patch and make sure the inner view is no more processed (ie the "masonry-processed" class is not rendered).
- Add a third Masonry view in a field of the teaser. Make sure this third inner view is masonry enabled but not the second.
Proposed resolution
Solution 1: Restraint the container (in template_preprocess_views_view_masonry() ) to the immediate inner ".view-content" of the view.
Solution 2: Build a unique ID for the view withing the template_preprocess_views_view_masonry() preprocess method and process that unique ID.
Remaining tasks
- make patch
- review patch
- commit
User interface changes
The inner views of a Masonry View will not be Masonry processed if not of masonry type themselves.
API changes
None
Impacts
Depending on if a user actually created his own template for the masonry view .tpl.php, solution 1 may break. Thus, solution 2 seems more efficient for that purpose.
Comments
Comment #1
Leon Kessler CreditAttribution: Leon Kessler commentedPatch attached which will ensure masonry is only applied on the correct View. This is done using a child CSS selector - so this could break someones implementation if they are injecting any custom markup. I have tested this with views headers and it works fine.
Comment #2
Leon Kessler CreditAttribution: Leon Kessler commentedComment #3
slcp CreditAttribution: slcp commentedWorks a treat for my use case though I haven't tested it extensively.
Comment #4
Dom. CreditAttribution: Dom. commentedI'm very sorry guys, I'm the new module maintainer and I don't intend to support multiple module versions.
Please update the 3.x (2.x will also deprecate when 3.x will be released) and try it.
Feel free to open a new issue if needed and provide a patch for 3.x version if your issue is still existing.
Thanks for your comprehension.
Comment #5
Leon Kessler CreditAttribution: Leon Kessler commentedLook to me like the 7.x-3.x version is a straight copy of the 7.x-1.x version. When I opened this ticket 1.x was the only dev version around.
This patch still applies cleanly to the new version, no need to start a new ticket :-)
Comment #6
Dom. CreditAttribution: Dom. commentedArgument accepted !
Could you explain how to reproduce for reviewing ? Are you talking about having a view B in the view A header or footer, or are you suggesting something more complex ?
Comment #7
Leon Kessler CreditAttribution: Leon Kessler commentedMy use case was this:
I had a view that displayed teasers (as opposed to fields), this view had the Masonry style applied to it.
My teasers contained another view, which was using the list style. Masonry was being applied to both views and causing things to mess up.
Haven't tried it with views inside the header or footer, it may also be an issue, it depends on the markup.
However, re-visiting the patch, it might be better to create our own unique selector. And use that in
masonry_apply()
, rather than guessing the markup outputted by views.Comment #8
Dom. CreditAttribution: Dom. commentedHow did you include a view in teader ? Display Suite ? Viewfield module ? Views Field View module ?
Comment #9
Leon Kessler CreditAttribution: Leon Kessler commentedIt was with panelizer.
I'd imagine those other methods would produce similar results though (correct me if I'm wrong).
Comment #10
Dom. CreditAttribution: Dom. commentedI have updated the issue summary. Also I will come with a patch for solution 2 which seems better for users with custom view templates that may not include .view-content and other depending markup.
Comment #11
Dom. CreditAttribution: Dom. commentedHere is a patch with solution 2. It does not depend on any upper template (views-view.tpl.php for example). Only the masonry template within the module.
Please have a try at it and let me know.
Comment #12
Leon Kessler CreditAttribution: Leon Kessler commentedThis could probably just be $unique_masonry_container no? There's no benefit of having the class names infront of it, and could lead to issues if someone is hacking their markup.
Comment #13
Dom. CreditAttribution: Dom. commentedI was wondering if needed in case of a view with multiple Masonry display.
Correction patch attached.
Comment #14
Leon Kessler CreditAttribution: Leon Kessler commentedLooks good, one small change...
Should be $container = '#' . $unique_masonry_container;
Comment #15
Dom. CreditAttribution: Dom. commentedThus this needs to be an ID.
Is it correct semantically speaking to have an ID here (ie within the .view-content) ?
Comment #16
Leon Kessler CreditAttribution: Leon Kessler commentedAh yes that needs to be changed too.
No problems having an ID here.
Comment #17
Dom. CreditAttribution: Dom. commentedDone it.
Comment #18
Leon Kessler CreditAttribution: Leon Kessler commentedReviewed and tested. Looks good!
Comment #20
Dom. CreditAttribution: Dom. commentedThanks @leon.nk
Comment #21
Dom. CreditAttribution: Dom. commentedThis correction needs to be reverted : it breaks Views Infinite Scroll compatibility :
#1808018: Make work with Views Infinite Scroll
Actually other modules may expect the markups to be standard, ie .view-content to contain only the rows, not in a nested markup.
Comment #22
Dom. CreditAttribution: Dom. commentedApplied first patch instead.
Comment #25
stevenx CreditAttribution: stevenx commented#1 works for me
thanks