Closed (fixed)
Project:
Views (for Drupal 7)
Version:
7.x-3.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
18 Mar 2012 at 17:12 UTC
Updated:
12 Apr 2019 at 21:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
kanani commentedthere's a views/theme/views-view-grouping.tpl.php file that theoretically could be used to add the $grouping_level.
template_preprocess_views_view_grouping() is what passes the value of $grouping_level through. However, in my views, I'm only ever seeing a value of 0
Comment #2
robdubparker commentedAny luck with this? I'm seeing all 0 values as well.
Comment #3
goldenboy commentedThe
groping_levelis always set to 0.Looking at the code there is a function in the style plugin that should use the group level as a param. Here the definition:
The default value for the param is 0 and there are no calls that pass the group level on.
Also, this function is called just one time per view. So, even if the group level is passed on, it will have always the same value.
Maybe the signature of this function should be changed and the group level should be passed on through the sets param.
The
setsparam is built by therender_groupingfunction. I think that could be the right place to do it.The attached patch fix this behavior just for the views_plugin_style.inc file. I left the signature of the render_grouping_sets function the same so nothing will be broken.
Comment #4
goldenboy commentedComment #5
goldenboy commentedSorry I made a little bit of confusion with the status values.
I re-attach the patch and set the status correctly.
Comment #6
scotwith1t/* hehe @ #3, groping_level */
so, related comment? if i group level one, it's a table caption, but if it's level 2 it's using the div.views-grouping-header being discussed here...is this related? is there a reason it's that way at level 1 and level 2 uses the div?
Comment #7
lunk rat commentedThanks, patch in #5 worked for me on 7.x-3.3. What I did:
Apply the patch in #5.
Copy
modules/views/theme/views-view-grouping.tpl.phpinto my theme's templates directory.Edit the copy of
views-view-grouping.tpl.phpso it looks like this:Clear views + theme cache.
Then I target the group-level-* class in my css.
Comment #8
rongok commentedIt still give me 0.
Comment #9
rongok commentedNow it works fine by adding $level++;
Thanks for the patch.
Comment #12
chrsnlsn commentedWhere did you add $level++ I added the patch cleared caches and am still just getting 0?
Comment #13
rongok commentedInside foreach() in render_grouping_sets function of views_plugin_style.inc
Comment #14
jibranLet's fix the bug first.
Comment #15
dawehner@Jibran
I think your fix will not really work, as it's just adding 1 all the time, so if level is 0 at the moment it will be just 1 all the time.
http://drupal.org/files/views-grouping-level-always-is-zero-1488744-3_0.... looks like a better fix,
though it doesn't seem to work for some people.
Comment #16
pmcdougl commentedPatch #5 works for me!
Comment #17
wooody commentedI think It will be better if we don't patch views files...
just copy this code and put it in your theme within file name views-view-grouping.tpl.php
Comment #17.0
wooody commentedtagging the code
Comment #18
solesum commentedThanks Wooody!
Comment #19
aquasplash commentedid is the wrong approach.
If you have more than one group, you get a bad result.
I tried a little bit to improve one of the patches.
Probably can be done more accurately.
But I managed to get the correct result in this way.
Comment #20
koechsle commentedStill a problem with Views 7.x-3.8.
Rather than patching Views or using $id (which only works for one group anyway) I managed to solve this by adding this to my theme's template.php.
It overrides the corresponding views theme function. The only difference is adding 1 to $vars['grouping_level'].
function MYTHEME_preprocess_views_view_grouping(&$vars) {
$vars['content'] = $vars['view']->style_plugin->render_grouping_sets($vars['rows'], $vars['grouping_level']+1);
}
Comment #21
lunk rat commentedYES! @koechsle your #20 is perfect, thank you so much! I was using #5 for over two years and just today I needed to update views and became very annoyed that I had to patch views just so that my CSS doesn't break, every time I update views.
So your template.php solution is a total win. Thanks again.
Comment #22
s.reichert commentedThis Bug still exists in Drupal 8.
#2508145: Grouping level is always zero in Views (Patch available)
Comment #23
cracu commented#20 is not working for me, but I used that hook to provide the correct grouping_level.
Helper function will simply parse the $vars['rows'] until no 'group' key is found in the first element.
group_levels will start with 1 -> that being the first wrapper of the content
Comment #24
discipolo commented#23 seems to work for me on initial test
Comment #25
tstoecklerSeems like a duplicate of #2508145: Grouping level is always zero in Views ?Edit: Sorry, wrong issue
Comment #26
jibran#2508145: Grouping level is always zero in Views got committed so this patch needs a reroll.
Comment #27
brightboldThanks for #20! A perfect workaround until this patch can get in.
Comment #28
tessa bakkerNew patch, with changes to the code and test as suggested in the D8 patch.
Comment #29
scotwith1tLove to see this get in! Also wondering about a group count class, like group-1, group-2, group-3, etc...perhaps odd/even group classes as well? first/last groups? might as well go all the way! :P
Comment #30
alex.skrypnyk#28 passed test and is actually working. Thank you! Marking for RTBC.
Comment #31
a.milkovskyBetter fallback to the default.
$level = isset($set['level']) ? $set['level'] : $level;
Else looks fine for me.
Comment #32
a.milkovskyFixed the issue from my last comment.
Comment #33
mustanggb commentedD8 does it as per #28 rather than #32, not sure of the relevance/consequence of this, just pointing it out.
Comment #35
damienmckennaGoing to go with #28, because it matches what D8 does. If this needs further work to change the default, please open a new issue for Views-D7 and for core-D8 so both can be the same.
Committed. Thanks!
Comment #36
LAguilar commentedFor my purposes #17 it worked for me