Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I propose something like
$output .= '<div class="view-grouping-header view-grouping-header-' . $grouping_level . '">' . $title . '</div>';
It would allow me to style the levels differently.
I don't know yet, where to get the grouping level, and if theme.inc is the right place to edit.
Comment | File | Size | Author |
---|---|---|---|
#32 | grouping_level_is-1488744-32.patch | 4.6 KB | a.milkovsky |
#28 | grouping_level_is-1488744-28.patch | 4.6 KB | Tess Bakker |
| |||
#19 | obtain-the-correct-level-1488744-19.patch | 1.44 KB | aquasplash |
Comments
Comment #1
kanani CreditAttribution: 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 CreditAttribution: robdubparker commentedAny luck with this? I'm seeing all 0 values as well.
Comment #3
goldenboy CreditAttribution: goldenboy commentedThe
groping_level
is 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
sets
param is built by therender_grouping
function. 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 CreditAttribution: goldenboy commentedComment #5
goldenboy CreditAttribution: 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 CreditAttribution: 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.php
into my theme's templates directory.Edit the copy of
views-view-grouping.tpl.php
so it looks like this:Clear views + theme cache.
Then I target the group-level-* class in my css.
Comment #8
rongok CreditAttribution: rongok commentedIt still give me 0.
Comment #9
rongok CreditAttribution: rongok commentedNow it works fine by adding $level++;
Thanks for the patch.
Comment #12
chrsnlsn CreditAttribution: chrsnlsn commentedWhere did you add $level++ I added the patch cleared caches and am still just getting 0?
Comment #13
rongok CreditAttribution: 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 CreditAttribution: pmcdougl commentedPatch #5 works for me!
Comment #17
wooody CreditAttribution: 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 CreditAttribution: wooody commentedtagging the code
Comment #18
solesum CreditAttribution: solesum commentedThanks Wooody!
Comment #19
aquasplash CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: s.reichert commentedThis Bug still exists in Drupal 8.
#2508145: Grouping level is always zero in Views (Patch available)
Comment #23
Cracu CreditAttribution: 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 CreditAttribution: 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
Tess 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 CreditAttribution: 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 CreditAttribution: LAguilar commentedFor my purposes #17 it worked for me