Problem/Motivation
A follow-up from exploratory testing done on #1843752-32: Convert views/templates/views-view-grouping.tpl.php to twig, I've found that the grouping
and grouping_level
variables, which are available, but never used by the views_view_grouping
template, have some fundamental issues:
- the
grouping
variable produces empty results (ie, an empty string), when printed in the template. This is broken only for twig. - the
grouping_level
variable always reports the level as0
(zero). This is broken for both twig and phptemplate.
Steps to reproduce:
This can be verified with either PHPTemplate and Twig, but the latter requires first applying a patch from #1843752: Convert views/templates/views-view-grouping.tpl.php to twig.
- Copy the views-view-grouping.tpl.php (or views-view-grouping.html.twig) template into Bartik's "templates" folder, so that it actually gets used.
- Edit the template file, adding two lines below to print out the two variables:
PHPTemplate<pre>Grouping: <?php print_r($grouping); ?></pre>
<pre>Grouping Level: <?php print $grouping_level; ?></pre>
Twig<pre>Grouping: {{ dump(grouping) }}</pre>
<pre>Grouping Level: {{ dump(grouping_level) }}</pre> - Create 2 articles.
- Edit front page view to have grouping on at least two fields (grouping on one field won't trigger the view-grouping markup). In the screenshot below, I used fields Node date, with the HTML Hours time format for the first level, and Node author name for the second level (which required a views relationship on the author of the post).
- View the front page.
Image may be NSFW.
Clik here to view.
Proposed resolution
What triggered the discovery of this issue was the lack of documentation for the grouping
variable in the template itself. The template's docblock documents this variable as "The grouping instruction", which is close to meaningless; and, after printing the variable to try to understand it, it is always empty.
So the proposed resolution would be to:
- Replace the grouping Array variable with separate individual variables useful to themers and improve the docblock.
- Fix grouping_level variable so it increments properly for each sub-grouping. The value should be equal to the grouping number "n" used in Views UI, minus 1.
Remaining tasks
User interface changes
None.
API changes
None.
Related Issues
Meta issue: #1843738: [meta] Convert views module to Twig
Discovered during #1843738: [meta] Convert views module to Twig
Discovered by #1843752: Convert views/templates/views-view-grouping.tpl.php to twig
Attachment | Size | Status | Test result | Operations |
---|---|---|---|---|
views-view-grouping-levels-always-zero.png | 163.78 KB | Ignored: Check issue status. | None | None |