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.
Meta issue: #1843738: [meta] Convert views module to Twig
#1987510: [meta] Convert all core *.tpl.php templates to Twig as singular patch
Manual testing steps:
1. Add some content
2. Add contextual filter
3. Under "WHEN THE FILTER VALUE IS NOT IN THE URL" select "display a summary" and select "unformatted"
Comment | File | Size | Author |
---|---|---|---|
#53 | 1843764-screenshot.png | 523.18 KB | tlattimore |
#41 | twig-views-view-summary-unformatted-1843764-41.patch | 4.84 KB | jwilson3 |
#41 | interdiff.txt | 638 bytes | jwilson3 |
#37 | interdiff.txt | 1.1 KB | shanethehat |
#37 | twig-views-view-summary-unformatted-1843764-37.patch | 5.27 KB | shanethehat |
Comments
Comment #1
joelpittetNeed to deal with this in a nicer way:
{{ row_classes[id] }}
Can someone point me in the right direction?
Comment #2
mbrett5062 CreditAttribution: mbrett5062 commentedTagging.
Comment #3
dawehnerI'm not 100% sure, but i guess the patch in #1773832: Replace usage of drupal_attributes, refactor to use Attribute better would make it easier.
Comment #4
joelpittetMoving to core queue
Comment #5
joelpittetTaking the original conversion, removing the tpl file and cleaning up $vars to $variables.
Comment #6
joelpittetNeeds Doc Cleanup to standards.
Comment #7
dawehnerThanks for your hard work on that!
The standard seems to be "Processes variables for blub.tpl.php".
If we change the line, please also drop the empty spaces.
Comment #8
joelpittetNeeds some clean up see #6 and #7
Comment #9
joelpittetCleanup from #6 and #7
Comment #10
joelpittetComment #11
star-szrTagging.
Comment #12
thedavidmeister CreditAttribution: thedavidmeister commentedReview for #9:
Trailing space on the second line.
The documentation for variables in the template could be better:
- No mention of what options is
- No mention of row_classes
- row.url is used but not described
- row.link is used but not described
- row.count is used but not described
'row.count' thi this option is set.
Grammatical error.
Show's the 'row.count'
Grammatical error.
Wraps items in a span if set to inline, or a div if not.
Unnecessary comma.
Template docs are missing
@see template_preprocess()
and@see template_preprocess_views_view_summary_unformatted()
Comment #13
star-szrThanks for reviewing @thedavidmeister. I'm tagging the documentation tweaks in #12 as a novice task.
If you'd like to work on this, please assign the issue to yourself. If you get stuck, drop by #drupal-twig on IRC or post your questions here. Thanks!
Comment #14
joelpittetChanges from #13
Comment #15
joelpittettypo and finger slip on the trigger there... there is a tab.. It's removed here.
Comment #16
thedavidmeister CreditAttribution: thedavidmeister commented+ * - count: An option to show/hide the 'count' to show the row's 'count'.
Still reads a bit weird. What about "A flag that indicates whether the row's 'count' should be displayed."
+ * - row_classes: A list of classes that correlate to each row by id.
ID
+ * - inline: Wraps each item in a span tag if set or a div if not set.
Well it's just a boolean, it doesn't "do" anything - we should be trying to separate the documentation of the variables from describing how the template implements markup using the variables. How about "A flag that indicates whether the item should be wrapped in an inline or block level HTML element"?
Comments should be on their own line, not "inlined" like this.
+ * - options: @todo.
I'm sure we can come up with *something* reasonable for this now.
Comment #17
star-szrTagging for profiling.
Comment #18
joelpittetThis should help out #16
Comment #19
thedavidmeister CreditAttribution: thedavidmeister commented+ * - options: Flags to change how each row will be displayed.
What about "Flags indicating how each row should be displayed." - just because they're still not "doing" anything. You can't say the flags "will change" anything, they're only flags.
Looking pretty good though.
Does anyone have steps to manually test this? I'm not sure exactly what it is :P
Comment #20
joelpittet#19 that may be a bit too nitpicky but I did it. "to change" is the ability to do something without necessarily doing anything. Like you said "will change" is the act of actually doing the possible.
Comment #21
thedavidmeister CreditAttribution: thedavidmeister commented#20 - thanks for that :) we just need some manual testing now.
Comment #22
star-szrCouple tiny tweaks here, correcting the @ingroup and rewrapping a comment that fits within 80 chars. Hope you don't mind @joelpittet :)
Comment #23
thedavidmeister CreditAttribution: thedavidmeister commentedaaaah i found the views summary!
1. Add some content
2. Add contextual filter
3. Under "WHEN THE FILTER VALUE IS NOT IN THE URL" select "display a summary" and select "unformatted"
doing some testing now
Comment #23.0
thedavidmeister CreditAttribution: thedavidmeister commentedUpdated issue summary.
Comment #24
thedavidmeister CreditAttribution: thedavidmeister commentedHEAD:
#22:
Diff:
Unfortunately this patch adds a new, empty class attribute to the links that doesn't exist in HEAD.
Comment #25
thedavidmeister CreditAttribution: thedavidmeister commentedComment #26
star-szrrow_classes is a misnomer because it's actually an Attribute object which can contain classes in the 'class' attribute.
PHPTemplate:
<a href="<?php print $row->url; ?>"<?php print $row_classes[$id]; ?>>
Twig:
<a href="{{ row.url }}" class="{{ row_classes[id] }}">
So the Twig version should probably look more like this:
<a href="{{ row.url }}"{{ row_classes[id] }}>
…and see the related issue #1968398: Convert Views $row_classes to $row['attributes'] for making this better :)
Comment #27
joelpittetDoc changes and fixes for #row_classes, reverted $variables back to $vars, leaving it to: #1963942: Change all instances of $vars to $variables
Comment #28
thedavidmeister CreditAttribution: thedavidmeister commented+ * - row_classes: A list of classes that correlate to each row by ID.
This is not what this is. It can either be "active" or nothing. I tried to add row classes to my view for testing #27 through the normal style option settings for "row class" and it didn't work.
First we do this:
Later we do this:
There's no "list of classes" and they don't correlate to rows by ID, they correlate to whether the url is active or not. I don't know why we aren't just using l() here but hey...
Comment #29
thedavidmeister CreditAttribution: thedavidmeister commented+ // Collect all arguments foreach row, to be able to alter them for example
"foreach" is "for each" in english :P
Comment #30
dmouseaccording to the documentation, its definition is:
now
Comment #31
gnugetComment #32
thedavidmeister CreditAttribution: thedavidmeister commentedBut you haven't changed this bit:
Which means that $vars['row_classes'][$id] can still never be anything other than an empty array() or array('active'). This is how HEAD behaves so we shouldn't change that here, but like I said in #28 we shouldn't document the variable in the Twig template as being a "list of classes" because it isn't. It's either an active class or nothing.
Comment #33
star-szrIt's important that it's still an Attribute object though, not just a string. So I think it should be documented as something like "HTML attributes for the row, either contains an 'active' class or no attributes."
Comment #34
thedavidmeister CreditAttribution: thedavidmeister commented#33 - Yup, just need to clean up the docs. Based on what's there at the moment I assumed that if I added "row classes" through the Views interface they would appear in my summary view but they do not.
Comment #35
thedavidmeister CreditAttribution: thedavidmeister commentedIf we could rename 'row_classes' to 'row_attributes' or something maybe that would make more sense?
Comment #36
star-szrYeah, #1968398: Convert Views $row_classes to $row['attributes'] for that :)
Comment #37
shanethehat CreditAttribution: shanethehat commentedRight, so how's this? I think it's important to continue to mention that the attributes (or attribute!) is keyed by the row ID, so this merges the existing text with #33.
Comment #38
star-szrAh right, it's an array of Attribute objects, not an Attribute object.
Change looks good to me, thanks @shanethehat!
This change can be rolled back, both do the same thing.
I'm wondering about all this docs cleanup within the preprocess function - can we leave that for another issue and focus on the Twig conversion here? I don't think we'd be patching these hunks otherwise. It's not Twig conversion's job to clean this up, we have enough to do already! :)
Comment #39
thedavidmeister CreditAttribution: thedavidmeister commented#38 - but undoing them once they're already done is also more work..
Comment #40
jwilson3Comment #41
jwilson3Backed out code, per #38. The rest I'll leave alone, per #39.
Comment #42
jwilson3Comment #43
jwilson3unassigning myself so someone can review.
Comment #44
intergalactic overlords CreditAttribution: intergalactic overlords commentedI have tested the html output. Is correct.
Comment #45
thedavidmeister CreditAttribution: thedavidmeister commentedComment #46
geoffreyr CreditAttribution: geoffreyr commentedProfiling.
Comment #47
geoffreyr CreditAttribution: geoffreyr commentedhttp://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519c0a514701f&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519c0a514701f&...
Comment #48
alexpottCan we get some understanding as to why the 1% performance regression....
Comment #49
star-szrThere are more function calls yes, wt only goes up 0.1% though. Can someone else run this please so we can get some more numbers?
Comment #50
tlattimore CreditAttribution: tlattimore commented@cottser: I will work on re-profiling this.
Comment #51
star-szrThe profiling results from #47 show that views-view-summary-unformatted was in fact not being used, @Fabianx and I just confirmed this. So this really needs re-profiling and needs to definitely use this template :) If you are not sure turn on twig_debug but ONLY for testing, turn off for profiling.
Thanks!
Comment #52
star-szrComment #53
tlattimore CreditAttribution: tlattimore commentedHere is my results from profiling this again. Very different from what cottser reported in #47, not sure why, but I ran it several times and even got a new baseline and ran it again.
Test Scenario
I then confirmed that the
views-view-summary-unformatted.html.twig
in the branch created from the work in #41 would be called in this scenario withtwig_debug
enabled (of course, I disabled twig_debug this prior to profiling). See attached screenshot for the scenario I profiled against.Run 519d9cf28420e uploaded successfully for drupal-perf-drupalcon.
Run 519d9d52c2102 uploaded successfully for drupal-perf-drupalcon.
=== 8.x..8.x compared (519d9cf28420e..519d9d52c2102):
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519d9cf28420e&...
=== 8.x..1843764-views-view-summary-unformatted compared (519d9cf28420e..519d9d94433aa):
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519d9cf28420e&...
---
ct = function calls, wt = wall time, cpu = cpu time used, mu = memory usage, pmu = peak memory usage
The registry has been rebuilt. [success]
'all' cache was cleared in self
Back to needs review to see what @cottser and @alexpott think about these results.
Comment #54
Fabianx CreditAttribution: Fabianx commentedLooks good to me. Is within measuring range and I cannot see any apparent slowdown.
=> Back to RTBC
Comment #55
alexpott+1. Ready for #1987510: [meta] Convert all core *.tpl.php templates to Twig as singular patch
Comment #56
alexpottCommitted e7d739a and pushed to 8.x. Thanks!
Comment #57.0
(not verified) CreditAttribution: commentedUpdated issue summary.