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.
Issue #1939090 by 2ndmile, hefox, Cottser, shanethehat, steveoliver, jenlampton, mr.baileys, derheap: Convert theme_tablesort_indicator() to Twig.
Task
Use Twig instead of PHPTemplate
Remaining
n/a
Profiling data
=== 8.x..8.x compared (519fe4bc90ab9..519fe53eaaaf2):
ct : 130,464|130,464|0|0.0%
wt : 646,158|644,671|-1,487|-0.2%
cpu : 640,039|640,041|2|0.0%
mu : 15,265,824|15,265,824|0|0.0%
pmu : 15,571,320|15,571,320|0|0.0%
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519fe4bc90ab9&...
=== 8.x..1939090-twig-sort-indicator compared (519fe4bc90ab9..519fe58959c26):
ct : 130,464|130,550|86|0.1%
wt : 646,158|646,620|462|0.1%
cpu : 640,039|640,040|1|0.0%
mu : 15,265,824|15,327,384|61,560|0.4%
pmu : 15,571,320|15,650,000|78,680|0.5%
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519fe4bc90ab9&...
Testing steps
Navigate to admin/appearance and set Stark as the admin theme.
Compare markup before and after applying the patch:
Navigate to admin/content, the tablesort indicator is in the "Updated" column header by default.
Related
#1885560: [meta] Convert everything in theme.inc to Twig
#1757550: [Meta] Convert core theme functions to Twig templates
#1973418: Remove tablesort-indicator.html.twig, use CSS instead
Comment | File | Size | Author |
---|---|---|---|
#60 | 1939090-60.patch | 2.63 KB | derheap |
#46 | 1939090-46.patch | 2.62 KB | star-szr |
#46 | interdiff.txt | 1.08 KB | star-szr |
#41 | interdiff.txt | 1.84 KB | shanethehat |
#41 | twig-convert_tablesort_indicator-1939090-41.patch | 2.83 KB | shanethehat |
Comments
Comment #1
hefox CreditAttribution: hefox commentedComment #2
hefox CreditAttribution: hefox commentednew line at end of file
Comment #3
hefox CreditAttribution: hefox commentedComment #4
joelpittet@hefox, nice work!
We may not really need a twig template for this one. Possibly:
keep your preprocess and replace:
theme('image', ...)
with
array('#theme' => 'image', ...)
Delete the twig file and the 'template' from the theme_hook.
That would be closer to ideal for me... but at the vary least we need to drop the theme() calls from this one. What do you think about dropping the twig file?
Comment #5
hefox CreditAttribution: hefox commentedI admit I was feeling rather silly making a .html.twig with just '{{ image }}' in it.
How about this? Less work for when seven needs to change just the uri
Comment #6
joelpittet@hefox, hell yeah! I would have not thought to use 'theme_hook_suggestions', does that have some benefits you would think over '#theme' => 'image'?
Not saying it's wrong, just haven't seen it used in the conversions yet, so I am curious, maybe I should be doing that as well in some cases.
Comment #7
hefox CreditAttribution: hefox commentedTruefully, I haven't used 7/8 enough to say which is better. Did a dsm to see what was in $variables, saw that, and figured I'd try it and it worked XD
Comment #8
steveoliver CreditAttribution: steveoliver commentedLet's see if this passes If so, it's what I'd do. Not sure about the t calls here.
Comment #9
hefox CreditAttribution: hefox commentedI don't think there is any tests that test if the tablesort icon correctly shows
It doesn't show as far as I can see http://gyazo.com/ef2a4867b9e90694b83697e3d98511cb ; also tried it with '#theme' = 'image'. No error messages. I don't know how the details of how the theme system works in 7/8, but I suspect it's too late to do that in a preprocess cause it's theme( and not render(.
I also tried 'image' => array('#theme' ... but didn't work.
Comment #10
steveoliver CreditAttribution: steveoliver commented#9, yeah, you're probably right. In that case, your #5 looks pretty good.
Comment #11
star-szrCan we please get some before/after screenshots testing #5?
Comment #12
mrf CreditAttribution: mrf commentedHere is the before after for #5
Before:
After:
Comment #13
hefox CreditAttribution: hefox commentedIt's changed colours (look closely) as the override is needed in the seven theme #1938848: seven.theme - Convert PHPTemplate templates to Twig
Comment #14
star-szrThis doesn't work when applied along with #1939068-26: Convert theme_image() to Twig, I'm hacking away at it.
Comment #15
star-szrAfter playing around with this, I think we should just go ahead and create tablesort-indicator.html.twig, no matter how basic – with the assumption that it will be removed/consolidated afterwards.
The hacks to make a preprocess function output through a different theme hook are not pretty, and I don't like the idea of the output from template_preprocess_tablesort_indicator() being output through image.html.twig, even temporarily. Too confusing. If I call theme('tablesort_indicator') I'd like to be able to assume there actually is a tablesort-indicator.html.twig that can be overridden. I don't want to have to find template_preprocess_tablesort_indicator() and see in the docs that it's a special case :)
So let's go ahead and create the template file with
{{ image }}
in it, please :)Comment #16
star-szrTagging as a Novice task to bring over this conversion from the sandbox.
I recommend taking a look at @c4rl's screencast: http://www.youtube.com/watch?v=HS4yKJjrb2E
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 #17
shanethehat CreditAttribution: shanethehat commentedComment #18
shanethehat CreditAttribution: shanethehat commentedComment #19
star-szrLooks good so far, thanks @shanethehat! We'll also need to remove theme_tablesort_indicator() and update drupal_common_theme() in theme.inc to add the 'template' key for the template we are adding.
Two small documentation nitpicks:
"Prepares" instead of "Prepare" per #1913208: [policy] Standardize template preprocess function documentation, and add a period after .html.twig for the Default template.
Let's change these to refer to our consolidation issue, something like this (would need to be wrapped and formatted per http://drupal.org/node/1354#todo):
@todo Remove this and consolidate with 'image', see http://drupal.org/node/1804614.
Also, in the preprocess function we need a line just containing
*
between the @params and this @todo.Comment #20
2ndmile CreditAttribution: 2ndmile commentedI'll take it.
Comment #20.0
2ndmile CreditAttribution: 2ndmile commentedAdd testing steps
Comment #21
2ndmile CreditAttribution: 2ndmile commentedChanges from #19 implemented. Does the @todo in the tablesort-indicator.html.twig also need to conform to the 80 character limit? If not, please review.
Comment #22
star-szrIgnore what I said about removing theme_tablesort_indicator() in #19, sorry about that :)
Trailing whitespace just before the @todo in preprocess, please remove per http://drupal.org/coding-standards#indenting.
The @todo should be wrapped and indented like this (nicely done), but 'see' can go on the first line.
Comment #23
2ndmile CreditAttribution: 2ndmile commentedChanges from #22 implemented.
Comment #24
2ndmile CreditAttribution: 2ndmile commentedWrapped comment in tablesort-indicator.html.twig. Please review.
Comment #25
thedavidmeister CreditAttribution: thedavidmeister commentedNitpick but, trailing whitespace was reintroduced in #24.
First line of:
Comment #26
2ndmile CreditAttribution: 2ndmile commentedWhitespace removed per #25. (What a newb, this 2ndMile guy...gees)
Comment #27
thedavidmeister CreditAttribution: thedavidmeister commented#26, I know I'm being picky, sorry!
The template uses attributes.src which is not documented here. Each property of attributes should be described on an indented new line - there's nothing official around that yet but pretty much all the other patches are doing that so it's kind of becoming a de facto standard.
Comment #28
star-szrI agree we should document src, but I'm not sure we need to describe all the other attributes in detail. In this case, let's just expand on 'src', and leave the rest of the attributes as an "inline" list if we can.
It looks like the 'src' variable doc in the template file is incorrect, that should be 'uri'.
Comment #29
2ndmile CreditAttribution: 2ndmile commentedLet me know if this is correct.
Comment #30
star-szr@2ndmile that looks pretty good to me but as per http://drupal.org/node/1354#lists the sub-list would need to be preceded by a colon (every list needs to be preceded by a colon). After looking at it I was thinking maybe we should just document each one on its own line - but #1939068: Convert theme_image() to Twig doesn't document any sub-attributes either.
I vote we use the same variable docs as image.html.twig #1939068: Convert theme_image() to Twig and use
<img{{attributes}} />
instead of<img src="{{ attributes.src }}"{{ attributes }} />
because the template is essentially a copy of image.html.twig.Comment #31
2ndmile CreditAttribution: 2ndmile commentedImplemented #30
Comment #32
star-szrThis is looking good, I will verify the markup once more but this look RTBC to me. Thanks @2ndmile :)
Comment #33
star-szrTweaked to add the 'typeof' attribute that was previously added via rdf_preprocess_image(), and moved the order of the attributes to match the current markup.
Before:
<img typeof="foaf:Image" src="http://d8.dev/core/misc/arrow-asc.png" width="13" height="13" alt="sort ascending" title="sort ascending" />
#31:
<img width="13" height="13" src="http://d8.dev/core/misc/arrow-asc.png" alt="sort ascending" title="sort ascending" />
This patch:
<img typeof="foaf:Image" src="http://d8.dev/core/misc/arrow-asc.png" width="13" height="13" alt="sort ascending" title="sort ascending" />
RTBC in my opinion but will leave it for someone else to review the code and docs once more.
Comment #34
star-szrAnd since 'attributes' is the main variable now, let's move it up in the list.
Comment #34.0
star-szradded meta
Comment #34.1
jenlamptonrm snad
Comment #35
jenlamptonwow, this looks really great. I almost marked it RTBC but found one small gramatical error, so decided to reroll. While in there I also added a link to a new issue I created specifically to remove this sucker. bwahahahaha!
Comment #36
thedavidmeister CreditAttribution: thedavidmeister commentedI added #1973418: Remove tablesort-indicator.html.twig, use CSS instead as an "after commit" issue on #1757550: [Meta] Convert core theme functions to Twig templates.
I'm going to review this now, hopefully mark it RTBC :)
Comment #37
thedavidmeister CreditAttribution: thedavidmeister commentedNitpick: Not even sure if it justifies a re-roll before RTBC considering we're planning to remove the whole template but:
Shouldn't the @todo be in it's own comment or part of the @file block? it seems awkward to have it "floating" just below the
*/
About to manually test the markup...
Comment #38
thedavidmeister CreditAttribution: thedavidmeister commentedHere's my manual check of the markup, confirming #33 but for patch #35:
before (link to ascending):
<img typeof="foaf:Image" src="http://localhost:8888/d8raw/core/misc/arrow-asc.png" width="13" height="13" alt="sort ascending" title="sort ascending" />
after (link to ascending):
<img typeof="foaf:Image" src="http://localhost:8888/d8html/core/misc/arrow-asc.png" width="13" height="13" alt="sort ascending" title="sort ascending" />
before (link to descending):
<img typeof="foaf:Image" src="http://localhost:8888/d8raw/core/misc/arrow-desc.png" width="13" height="13" alt="sort descending" title="sort descending" />
after (link to descending):
<img typeof="foaf:Image" src="http://localhost:8888/d8html/core/misc/arrow-desc.png" width="13" height="13" alt="sort descending" title="sort descending" />
Comment #39
shanethehat CreditAttribution: shanethehat commentedDoesn't the change introduced in #33 enforce an RDF attribute even when the RDF module is disabled? I thought it would be preferable to pass a render array using #theme => image to the template, so that any registered image theme hooks would still be applied. If I'm wrong, please correct me because it will impact the work I'm done on #1898420: image.module - Convert theme_ functions to Twig.
Comment #40
star-szrNo, you're absolutely right @shanethehat. Didn't think of that.
Comment #41
shanethehat CreditAttribution: shanethehat commentedFixes the question from #39, and adds spaceless tags to ensure no trailing spaces after an inline element.
Comment #42
star-szrCode looks good, thanks @shanethehat! Can we get one more manual test (markup comparison) please? Testing steps are up in the issue summary.
Comment #43
thedavidmeister CreditAttribution: thedavidmeister commentedyeah I'll do it.
Comment #44
thedavidmeister CreditAttribution: thedavidmeister commentedJust checking the "after" HTML since the "before" HTML is already in #38:
<img typeof="foaf:Image" src="http://localhost:8888/d8raw/core/misc/arrow-asc.png" width="13" height="13" alt="sort ascending" title="sort ascending" />
<img typeof="foaf:Image" src="http://localhost:8888/d8raw/core/misc/arrow-desc.png" width="13" height="13" alt="sort descending" title="sort descending" />
Comment #45
thedavidmeister CreditAttribution: thedavidmeister commentedComment #46
star-szrJust removing consolidation todos - see #1757550-38: [Meta] Convert core theme functions to Twig templates for reasoning.
Comment #47
alexpottComment #48
mr.baileysI'll profile this one.
Comment #49
mr.baileysFinished profiling:
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519fd0873c1d7&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519fd0873c1d7&...
Comment #50
mr.baileysSince this was RTBC prior to the profiling request, and since profiling shows a slight performance improvement, I'm going to go ahead and set this back to RTBC.
Comment #51
mr.baileysHold on. I double-checked this patch by enabling twig_debug, and the template is not showing up. Trying to figure out what's happening...
Comment #52
mr.baileysOk, my first profiling runs used Seven, where the tablesort indicator is overriden, and the twig template file is not used. I re-ran the numbers, this time using Stark and making sure that the tablesort-indicator.html.twig template is used:
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519fe4bc90ab9&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519fe4bc90ab9&...
Comment #53
joelpittetGreat work @mr.baileys thanks for profiling this!
Seems to be within the margin of error.
Comment #54
star-szr#46: 1939090-46.patch queued for re-testing.
Comment #56
star-szr#46: 1939090-46.patch queued for re-testing.
Comment #57
star-szrBack to RTBC per #53. Was just making sure this still applied.
Comment #58
star-szrNo longer applies, needs a quick reroll.
Comment #59
derheap CreditAttribution: derheap commentedTrying reroll.
Comment #60
derheap CreditAttribution: derheap commentedComment #61
star-szrReroll looks good, thanks @derheap!
Comment #63
star-szr#60: 1939090-60.patch queued for re-testing.
Comment #63.0
star-szrrelated
Comment #63.1
star-szrAdd commit message and profiling data
Comment #64
star-szrBack to RTBC. Added the profiling data and a commit message to the issue summary.
Also did one more round of manual testing with and without RDF enabled and this is still looking good. Thanks everyone!
Comment #65
alexpottCommitted 9ee90ca and pushed to 8.x. Thanks!
Comment #66.0
(not verified) CreditAttribution: commentedAdd something in remaining