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.
Task
Use Twig instead of PHPTemplate
Remaining
Replace all theme functions and templates with .html.twig equivalent templatesAdd new preprocess functions for the .html.twig equivalent templates if nessasaryUpdate all hook_theme definitions
Steps to reproduce
- Enable tracker module.
- Generate some nodes
- Create a 'test' user and visit half the nodes with that user.
- Update those nodes as admin.
- Visit /tracker/ to see mark template in action.
Comment | File | Size | Author |
---|---|---|---|
#74 | twig-convert_mark-1939092-74.patch | 1.99 KB | mgifford |
#66 | twig-convert_mark-1939092-66.patch | 1.97 KB | dbazuin |
Comments
Comment #1
larowlanthe last one was too easy
Comment #2
larowlanYou guys have made this too easy, surely I'm missing something?
Comment #3
joelpittetHaven't seen how constants work in twig... my guess is they don't. Changing to needs review to get testbot's answer.
Comment #4
joelpittetWell I am surprised that passed the tests, maybe it needs more tests?
I did a manual test to see what {{ MARK_UPDATED }} gives me which was zip followed by the usual
MARK_UPDATED could not be found in _context
Comment #5
star-szrThis might be helpful:
http://twig.sensiolabs.org/doc/tests/constant.html
Comment #6
star-szrAlthough if it's not a class constant it looks like maybe you don't need to use that syntax, not sure.
There are tests for markers in \Drupal\system\Tests\Form\ElementsLabelsTest.So I think this is just legitimately working :)Edit: Could be there are no tests, haven't looked thoroughly.
Comment #7
joelpittetJust did a search, yeah there are no tests. @larowlan Could you possible write some simple tests to see if the output is what we are looking for?
Also, could you pass those constants through the preprocess to the twig file so they are available. I talked briefly with FabianX about this this morning and that may be the quickest solution for now.
Comment #8
larowlanSure
Comment #9
larowlanHang on, I'm certain there are tests for this in the CommentInterface tests (after spending hours debugging them for #731724: Convert comment settings into a field to make them work with CMI and non-node entities).
Going for a look-see.
Comment #10
larowlanAh but they run in standard profile which uses Bartik...
So we need some new tests that use stark.
Comment #11
larowlanSo, turns out - there are tests in tracker module for the new functionality - and these use Stark.
But the twig patch above didn't include the required drupal_common_theme() update to reference the template, so kept using the theme_mark() function, hence it passed.
Please find attached an interdiff from 2, a patch that includes the template entry in drupal_common_theme (and will fail because of the constants in the twig file) and a pass patch that introduces the constants as variables in the twig template preprocessing.
Comment #12
larowlanComment #13
star-szrThanks @larowlan! We'll need to remove theme_mark(), and the preprocess docs could be updated to meet #1913208: [policy] Standardize template preprocess function documentation.
Comment #14
larowlanThanks, I wasn't aware that all core themes used Twig, but if we're removing theme_mark() then I guess they are.
Also updated preprocess docblock.
Comment #15
joelpittetSmall cleanup, may still need some tests, not sure thoughts? Otherwise RTBC?
Comment #16
larowlanThere are tests in the tracker module.
I assume this wasn't supposed to be here :)
Comment #17
joelpittetHmm... let's try that again shall we. I'll get my workflow down eventually:S
Comment #18
larowlanThis looks good to go to me but I don't think I'm eligible to RTBC it.
Comment #19
tlattimore CreditAttribution: tlattimore commentedIs there a reason that these array keys are all caps? According to the coding standards all variable names should be lower case. http://drupal.org/coding-standards#naming
Comment #20
star-szrAfter doing some testing while working on #1898054: comment.module - Convert PHPTemplate templates to Twig, Twig's constant function works quite well and I think we should embrace it:
http://twig.sensiolabs.org/doc/functions/constant.html
This passes tracker tests locally.
Also tweaked the docs a bit.
Comment #21
thedavidmeister CreditAttribution: thedavidmeister commentedI can't see anything wrong with this.
"updated" test in TrackerTest.php is in testTrackerCronIndexing().
"new" test in TrackerTest.php is in testTrackerNewNodes().
Comment #22
thedavidmeister CreditAttribution: thedavidmeister commented#20: 1939092-20.patch queued for re-testing.
Comment #23
star-szrThanks @thedavidmeister!
Two minors tweaks, leaving at RTBC:
Comment #24
star-szrI messed up, the actual patch from #28 doesn't include the changes from the interdiff. I was experimenting with http://hojtsy.hu/blog/2012-apr-13/quick-and-simple-interdiffs and missed a step. Here's the correct patch with docs tweak (patch + interdiff).
Comment #25
alexpottComment #26
joelpittetNeeds a re-roll, patch #24 doesn't apply any longer.
Comment #27
pwieck CreditAttribution: pwieck commentedRe-rolling #24 now
Comment #28
pwieck CreditAttribution: pwieck commentedre-rolled.
Comment #29
thedavidmeister CreditAttribution: thedavidmeister commentedThis re-roll seems to be a regression on #2010672: Rename 'type' variable of theme_mark to 'status'
Comment #30
pwieck CreditAttribution: pwieck commentedI will fix re-roll, this should not be in there -> function theme_mark($variables) {Only interdiff file is wrong. Patch is correct
Thanks @thedavidmeister
Comment #31
thedavidmeister CreditAttribution: thedavidmeister commentedis a problem in that patch.
Comment #32
pwieck CreditAttribution: pwieck commented@thedavidmeister The patch is right the interdiff.txt file is wrong for some reason. Good for review just disregard interdiff.txt
Comment #33
thedavidmeister CreditAttribution: thedavidmeister commentedthe patch in 28 is wrong because of
Comment #34
pwieck CreditAttribution: pwieck commentedSorry I see now. I thought this was my error. This was in the original patch. So it should be
This
'variables' => array('mark_type' => MARK_NEW),
Not this
'variables' => array('type' => MARK_NEW),
Everything else is correct in patch?
Comment #35
pwieck CreditAttribution: pwieck commented@thedavidmeister,
Changed:
'variables' => array('type' => MARK_NEW),
To:
'variables' => array('mark_type' => MARK_NEW),
Comment #37
pwieck CreditAttribution: pwieck commentedKicking this back to the coders. I'm am just a re-roll monkey. Doesn't pass test.
Could it be this area in patch?
Comment #38
thedavidmeister CreditAttribution: thedavidmeister commentedyeah, basically anything that was "type" should probably be "mark_type" now
Comment #39
pwieck CreditAttribution: pwieck commentedI'm a novice and trying to understand this part of the code.
How can starting with this:
Then applying patch:
Suppose to work and ending up like this:
I don't see where the styling is anymore
Comment #40
thedavidmeister CreditAttribution: thedavidmeister commentedIt is in the Twig template:
Comment #41
pwieck CreditAttribution: pwieck commentedDuh? I seen that too. Been re-rolling all day and into the night, guess I should sleep. I am not experienced enough to diagnose the patch failure.
Thx @thedavidmeister for taking the time to help me.
Comment #42
thedavidmeister CreditAttribution: thedavidmeister commentedprobably failing because the Twig template is still referencing 'type' (in the code and the docs) instead of 'mark_type'.
Comment #43
star-szrYep, agreed with #42. Thanks for all your work on this @pwieck :D
Comment #44
azinoman CreditAttribution: azinoman commenteddibs
Comment #45
azinoman CreditAttribution: azinoman commenteddibs
Comment #46
pwieck CreditAttribution: pwieck commentedNeed to remove @see template_preprocess()
[policy adopted, patch needed] Stop saying '@see template_preprocess()' in every twig file
Comment #47
azinoman CreditAttribution: azinoman commentedI changed the initial mark_type to just type under the instruction of Jen Lampton. I think that should fix everything now. Changing to needs review.
Comment #49
thedavidmeister CreditAttribution: thedavidmeister commentedPlease don't do this.
If you do this:
Then drupal_render() thinks you're trying to render a 'foo' element and pulls up those defaults from element_info(). theme('mark') is then in appropriately using the #type attribute to render itself not based on the element type at all.
What's worse is that using #type like this means it is impossible for us to ever implement #type 'mark' in the future.
I don't mind if you want to rename the variable to something other than 'mark_type' but 'type' is not an option.
I just opened #2024743: Document "reserved variables" for renderables to avoid conflicts with drupal_render(), the FAPI, and _theme() so hopefully conflicts like this will be more obvious in the future.
Comment #50
pwieck CreditAttribution: pwieck commented@azinoman - Please see #46, @see template_preprocess() is still in patch and needs to be removed.
Comment #51
jenlamptonSorry about that. Here I've changed 'type' to 'status' which is a better indication of what the heck a 'mark' is anyway.
Also removed that @see
Comment #53
star-szrWe just changed it to mark_type in #2010672: Rename 'type' variable of theme_mark to 'status' and there's a pending change notice for that. So I am okay with changing it again but it should happen over there IMO.
Comment #54
jenlamptonpostponing this then, on https://drupal.org/node/2010672
Comment #55
jenlamptonAlso, will need a reroll after that gets in. So, tagging.
Comment #56
jenlamptonunpostponed! :) woot.
edit: whoops, forgot to remove reroll tag, plz do so when reviewing :)
Comment #57
star-szrHmm, looking at this again - why do we set the logged_in variable in preprocess? It's a default template variable that should be getting set in _template_preprocess_default_variables!
This means:
Comment #58
jenlamptonLOVE IT :)
removed the preprocess function and the docs lines about the variable, and also @see
Comment #60
jenlamptontrying again. sorry test bot!
Comment #61
thedavidmeister CreditAttribution: thedavidmeister commentedThis needs manual testing as well, I can't see that it has been done anywhere in this thread.
The manual testing is a novice task.
Comment #62
joelpittetI think this got lost, so I added it back to #1757550: [Meta] Convert core theme functions to Twig templates
Needs a re-roll
Comment #63
joelpittet#60: twig-convert_mark-1939092-60.patch queued for re-testing.
Comment #65
dbazuin CreditAttribution: dbazuin commentedI rerolled the patch
Comment #66
dbazuin CreditAttribution: dbazuin commentedNovice mistake sorry.
This is the good patch
Comment #67
mikl CreditAttribution: mikl commentedI'll test this.
Comment #68
mikl CreditAttribution: mikl commentedVerified that the template is actually used.
The best way to test this is the tracker page, where the mark template will be rendered for each node (regardless of its status). This will likely have mean a significant performance hit, but we'll need someone to run an actual profiling to see how bad it is.
Comment #68.0
adsw12 CreditAttribution: adsw12 commentedRemoved link sandbox and added a new a related link
Comment #69
joelpittetpostponing on #1311372: Use <mark> element for 'mark' theme hook
Comment #69.0
joelpittetUpdated issue summary.
Comment #70
star-szrComment #71
markhalliwellWe shouldn't postpone the initial conversion on #1311372: Use <mark> element for 'mark' theme hook. Changing existing markup should happen afterwards.
Comment #72
markhalliwellJust an FYI (as a @todo) this will not be necessary once #2226207: Make 'template' the default output option for hook_theme() gets in.
I'd like to RTBC this as it's a pretty straight forwards conversion, but it needs to be re-rolled and also profiled.
Comment #73
markhalliwellComment #74
mgiffordreroll
Comment #75
joelpittetThanks @mgifford, this now needs some manual testing.
Comment #76
andypostand profiling... I think tracker page is a nice example
Comment #77
mgifford@andypost do you mean /user/1/track
I'm not sure where to best find this in Core.
Comment #78
joelpittetI double checked #68 and it seems to be rendering before and after the patch exactly the same.
For profiling you may need to build a contrived example because it could be tricky to run xhprofkit with a logged in user, our normal approach has been with anonymous.
Added steps to test in the issue summary.
Comment #79
markhalliwellI'm inclined to say that this actually doesn't need profiling now that I really think about it. The conversions that really need it are things like tables, images, etc. This is a very, very simple patch/conversion (ie: they both ultimately are just a PHP function that spits out simple markup).
That being said, I just manually tested this in simplytest.me and it appears to be working on node comments correctly. I did notice that when my second user updated a comment it still said "new", not "updated". Not sure if this is because of this issue or a bug in how we handle these markers on the front-end now (ie: separate bug/issue).
I'm going to leave this as CNR and tag with manual testing so someone else can take a look at this in more depth (locally).
Comment #80
steinmb CreditAttribution: steinmb commentedLet me take it for a spin
Comment #81
steinmb CreditAttribution: steinmb commentedShort story it works. There is a slight change in the markup though we could perhaps address some in a followup issue where we polish, discuss and argue about markup.
Before, logged in user:
Before, logged out user:
<td><a href="/node/4">foobar</a> </td>
After twig conversion, logged in user:
Logged out user:
<td><a href="/node/4">foobar</a> </td>
Comment #82
markhalliwell74: twig-convert_mark-1939092-74.patch queued for re-testing.
Comment #83
joelpittetThanks for the manual testing, would you mind creating a follow up issue to maybe consider moving the logic to the preprocess or maybe remove this template and leave the domain logic up to the domain (node) if possible?
@Mark Carver has some ideas on how we can remove this template but I'd like that to move to follow up and just get this in and done.
Comment #84
markhalliwellAgreed, RTBC. Went ahead and created the follow-up (which is postponed anyway).
Comment #85
star-szr+1, looks good to me.
Comment #87
joelpittetrandom fail?
Comment #88
webchick74: twig-convert_mark-1939092-74.patch queued for re-testing.
Comment #89
webchickCommitted and pushed to 8.x. Thanks!