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
Convert PHPTemplate templates to Twig templates.
Remaining
- theme_ function -> Twig conversions (and preprocess function additions or changes) moved over from the existing conversion issue
specifically:Theme function name Conversion status theme_field converted in this issue. theme_field_multiple_value_form done. converted in this issue bartik_field__taxonomy_term_reference converted here instead of in #1938840: bartik.theme - Convert PHPTemplate templates to Twig for dependency reasons Profiling. done in #23 and #41, nothing changed that would require reprofiling
To test this code:
Edit image fields on an article to include multiple images.
create an article
add a tag
add two images
add a body
Related Issues
#1898062: field.module - Convert PHPTemplate templates to Twig
#1757550: [Meta] Convert core theme functions to Twig templates
#1987510: [meta] Convert all core *.tpl.php templates to Twig as singular patch
Comment | File | Size | Author |
---|---|---|---|
#122 | interdiff.txt | 689 bytes | star-szr |
#122 | 1987398-122.patch | 15.95 KB | star-szr |
#121 | interdiff.txt | 1.46 KB | rteijeiro |
#121 | drupal-field_module_convert_theme_functions_to_twig-1987398-121.patch | 15.95 KB | rteijeiro |
#111 | interdiff-1987398-106-111.txt | 1.9 KB | RainbowArray |
Comments
Comment #0.0
star-szrUpdated issue summary.
Comment #1
c4rl CreditAttribution: c4rl commentedPer #1757550-44: [Meta] Convert core theme functions to Twig templates, retitling to indicate this issue applies to theme_ functions rather than templates. See #1898062: field.module - Convert PHPTemplate templates to Twig for template conversion.
Comment #1.0
c4rl CreditAttribution: c4rl commentedUpdated issue summary.
Comment #1.1
c4rl CreditAttribution: c4rl commentedUpdated issue summary.
Comment #1.2
c4rl CreditAttribution: c4rl commentedUpdated issue summary.
Comment #1.3
star-szrUpdated issue summary.
Comment #2
star-szrHere are just the theme_ function conversions. Taking a guess that the fix in #1898062-41: field.module - Convert PHPTemplate templates to Twig is needed here and not there.
Comment #2.0
star-szrUpdated issue summary.
Comment #2.1
star-szrUpdate info about theme_field
Comment #3
Hanpersand CreditAttribution: Hanpersand commented#2: 1987398-2.patch queued for re-testing.
Comment #4
gg4 CreditAttribution: gg4 commented(removed)
Comment #5
lucascaro CreditAttribution: lucascaro commented#2: 1987398-2.patch queued for re-testing.
Comment #6
carsonevans CreditAttribution: carsonevans commentedI am unable to apply this patch to the current 8.x branch. Not profiling.
Comment #7
gg4 CreditAttribution: gg4 commentedComment #8
lucascaro CreditAttribution: lucascaro commentedconfirmed by testbot that this patch fails
Comment #9
gnugetComment #10
gnugetA reroll of #2
Comment #11
joelpittet#10 needs manual testing and steps to profile and steps to manual test. Tagging.
Comment #12
star-szrFixing up tags.
Comment #13
thedavidmeister CreditAttribution: thedavidmeister commentedmanual testing is a novice task
Comment #14
adamcowboy CreditAttribution: adamcowboy commentedI manually tested the following 3 things:
A field with single value
A taxonomy term reference field in bartik
A field with two values
Comment #15
adamcowboy CreditAttribution: adamcowboy commentedChanging status <3.
Comment #15.0
adamcowboy CreditAttribution: adamcowboy commentedUpdated issue summary.
Comment #16
alexpottLets get some profiling of this change...
Comment #17
jenlamptonchanging back to NR
Comment #18
jerdavisI was going to profile this, but it needs a re-roll so I'm re-rolling :)
Comment #19
jerdavisRe-roll of patch
Comment #21
jerdavisRe-roll to remove the following lines from tests
+ $this->installSchema('user', array('role_permission'));
role_permission table was dropped with the commit from https://drupal.org/node/1872876
Comment #22
jerdavisComment #23
jerdavisScenario:
- Set image field on Article to multiple value
- Generate 50 articles
=== 8.x..8.x compared (51ec623000e0c..51ec6582d0962):
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=51ec623000e0c&...
=== 8.x..1987398-field.module compared (51ec623000e0c..51ec66a5a877d):
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=51ec623000e0c&...
Comment #24
star-szrTagging for reroll.
Comment #25
joelpittetRe-rolled
Comment #27
joelpittet#25: 1987398-25-twig-theme-field.patch queued for re-testing.
Comment #28
joelpittetWe can't have a @todo in here, if this is going to land then we should get that one going, but in the meantime I think we just remove the @todo.
This @todo and it's related variable to string cast (
'' ~
) should no longer be needed due to #1975462: Allow and test for NULL and integer 0 values in Twig templates.Comment #29
adsw12 CreditAttribution: adsw12 commentedWorking on it.
Comment #30
adsw12 CreditAttribution: adsw12 commentedWorking on it.
Comment #31
adsw12 CreditAttribution: adsw12 commentedRe-relloded the patch addressed all the comments from @joelpittet #28
Comment #32
adsw12 CreditAttribution: adsw12 commentedRemoved string cast ('' ~) #25
Comment #33
joelpittetThanks @adsw12 and nice to meet you at drupalcon prague.
This issue is ready for manual testing and that should be it for this one:)
Comment #34
star-szrIf we are removing theme_field() then we should also update field.html.twig to remove the HTML comment:
The profiling results actually look reasonable to do this from what I can see!
Comment #35
joelpittetThese don't exist either.
Comment #36
dsayswhat CreditAttribution: dsayswhat commentedRe-roll of #32.
Comment #37
dsayswhat CreditAttribution: dsayswhat commentedEdited documentation to address #34 and #35.
Comment #38
dsayswhat CreditAttribution: dsayswhat commentedSetting to needs review
Comment #39
joelpittetJust going to check that I get the same results as #23. Crossing fingers because that would be great:)
Comment #40
star-szrAwesome @dsayswhat, thanks! An interdiff is always good to include when updating patches - in this case we lost a couple files between #36 and #37:
core/modules/field/templates/field-multiple-value-form.html.twig
core/themes/bartik/templates/field--taxonomy-term-reference.html.twig
Comment #41
joelpittetOk bench is the same scenario as #23 and I used the patch from #36.
Looks great still. Just need #37 fixed up and provide an interdiff.
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=5251f592ab279&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=5251f592ab279&...
Comment #42
Tim Bozeman CreditAttribution: Tim Bozeman commentedComment #43
Tim Bozeman CreditAttribution: Tim Bozeman commentedI took the missing files:
core/modules/field/templates/field-multiple-value-form.html.twig
core/themes/bartik/templates/field--taxonomy-term-reference.html.twig
from the patch on #36 and added them to the patch on #37.
Comment #44
Tim Bozeman CreditAttribution: Tim Bozeman commentederrrgh
Comment #45
star-szrNice @Tim Bozeman! Let's also remove the
@see template_process_field()
lines mentioned by @joelpittet in #35.Comment #46
Tim Bozeman CreditAttribution: Tim Bozeman commentedOkay
Comment #47
Tim Bozeman CreditAttribution: Tim Bozeman commentedA few changes to the #43 patch.
As requested by @Cottser in #45:
Removed the @see template_process_field() lines mentioned by @joelpittet in #35.
Also, @Cottser mentioned in #34 that theme_field() is gone so I removed a line in the comment of field.html.twig and a sentence from a comment on line 694 of field.module that referenced theme_field().
Comment #48
Tim Bozeman CreditAttribution: Tim Bozeman commentederrrgh
Comment #49
star-szrI think we should change the reference in field.module to theme_field() to field.html.twig instead of removing it.
Comment #50
Tim Bozeman CreditAttribution: Tim Bozeman commentedThird times the charm!
Comment #51
Tim Bozeman CreditAttribution: Tim Bozeman commentederrrgh
Comment #53
Tim Bozeman CreditAttribution: Tim Bozeman commentedSorry for the spam! : /
Comment #54
joelpittet@Tim Bozeman now worries for the spam, thank you very much for doing those changes:)
There has been manual testing in #14 but we should probably do another round just to be safe we didn't make any mistakes. @Tim Bozeman you're welcome to give that a try too or someone else can pick this issue up from here.
Comment #55
Tim Bozeman CreditAttribution: Tim Bozeman commentedComment #55.0
Tim Bozeman CreditAttribution: Tim Bozeman commentedAdded to test section :).
Comment #55.1
YesCT CreditAttribution: YesCT commentedtrying to clarify and update cause refereneced issues are closed and such
Comment #56
Tim Bozeman CreditAttribution: Tim Bozeman commented#53 was stale, rerolled.
Comment #57
markhalliwell@joelpittet, could you double check this this? Thanks!
Comment #58
joelpittetLooking:)
Comment #59
joelpittetReviewed the markup from #56
The following templates were rendered onto the article page I tested:
Other than whitepace differences there was issues.
The two files uploaded were used for comparison, the modifications were to the hash keys and whitespace to make the diffs easier to parse.
Thanks @Tim Bozeman for finishing that up.
Profiling done in #41 is still good, no changes to speak of that would make a difference between #36 and #56
Comment #60
star-szrTagging for reroll.
Comment #61
Nigel_S CreditAttribution: Nigel_S commentedComment #62
Nigel_S CreditAttribution: Nigel_S commentedChanges to the FieldDefinitionInterface and the placing of '#cardinality_multiple' as a key in $variables broke the old patch. The patch also had snippets of $output being constructed so I've stripped those too.
Comment #63
Nigel_S CreditAttribution: Nigel_S commentedComment #64.0
(not verified) CreditAttribution: commentedtheme_field() hasn't been removed (yet)
Comment #65
Nigel_S CreditAttribution: Nigel_S commentedMissed out a line from #62, oops. Between the patch on 2013-10-22 and now CARDINALITY_UNLIMITED was moved to the FieldDefinitionInterface and a '#cardinality_multiple' key has been added to $element alongside cardinality.
Comment #67
joelpittet65: drupal8.field-system.1987398-65.patch queued for re-testing.
Comment #68
joelpittet65: drupal8.field-system.1987398-65.patch queued for re-testing.
Comment #70
Nigel_S CreditAttribution: Nigel_S commentedSince the last reroll the format of the taxonomy field has changed within Bartik - introduced bartik_preprocess_field to conditionally apply .visually-hidden - this lets screen readers still read the label even when it's hidden.
Comment #72
Nigel_S CreditAttribution: Nigel_S commented70: drupal8.field-system.1987398-70.patch queued for re-testing.
Comment #73
Nigel_S CreditAttribution: Nigel_S commentedSame patch that passed testing above (first fail was due to broken HEAD) but with some comment errors corrected.
Comment #74
joelpittet@Nigel_S thanks for the patches, great to see them green. Here's a little nit-pick doc change as well. And I think this is ready for manual testing again.
This is not being used. we should remove it.
Comment #75
Nigel_S CreditAttribution: Nigel_S commented@joelpittet - thanks :) have removed that line of the comment - everything else unchanged
Comment #76
star-szrInterdiff please! Thanks @Nigel_S :)
Comment #76
star-szrdouble post.
Comment #78
Nigel_S CreditAttribution: Nigel_S commented75: drupal8.field-system.1987398-75.patch queued for re-testing.
Comment #79
Nigel_S CreditAttribution: Nigel_S commentedOh alright :P apparently I also killed some whitespace
Comment #81
Nigel_S CreditAttribution: Nigel_S commented75: drupal8.field-system.1987398-75.patch queued for re-testing.
Comment #83
Nigel_S CreditAttribution: Nigel_S commentedSorry for the re-test spam; it seems testbots are dying due to out-of-memory errors - will hold off on re-testing again until https://drupal.org/node/2141501 is dealt with.
Comment #84
Nigel_S CreditAttribution: Nigel_S commented75: drupal8.field-system.1987398-75.patch queued for re-testing.
Comment #85
Jeff Burnz CreditAttribution: Jeff Burnz commentedCould we just use "multiple"?
Haven't tested but great patch, looks good.
Comment #86
joelpittet@Jeff Burnz that sounds like a slightly easier to understand variable name. Cardinality is a $100 word for a 5cent concept. Let's make that change.
Comment #87
Nigel_S CreditAttribution: Nigel_S commentedOK :) These changes switch the variable to 'multiple' - I also noticed when looking at it that check_plain is now deprecated so I've switched template_preprocess_field to a direct call to String::checkPlain.
Comment #88
star-szrThanks for your continued work on this issue @Nigel_S! Here are some things that can be fixed up:
@see template_preprocess_field_multiple_value_form()
This docblock needs some more spacing out (blank line after the summary line and around the @see), and the summary line needs to end in a period per http://drupal.org/node/1354#drupal.
Blank line before @ingroup line please, similar to the above.
Extra space in here, should be
<h3{{ label_attributes}}>
. The attribute object will print out the leading space if there are any attributes, otherwise you get a nice clean<h3>
:)Comment #89
Nigel_S CreditAttribution: Nigel_S commentedOK, done :)
Comment #90
Nigel_S CreditAttribution: Nigel_S commentedComment #91
joelpittet@Nigel_S wanna grab the re-roll on this one?
Comment #92
joelpittet89: drupal8.field-system.1987398-89.patch queued for re-testing.
Comment #94
Nigel_S CreditAttribution: Nigel_S commentedYeah sure, I shall take a look at it
Comment #95
Nigel_S CreditAttribution: Nigel_S commentedRe-rolling
Comment #96
star-szrThanks @Nigel_S!
Here's another review :)
These comments should be complete sentences and the second line is a couple characters over 80.
This could be more specific/instructive and say "Use bartik_theme_prepare_field__taxonomy_term_reference when https://drupal.org/node/2035055 is resolved".
The indenting is off in the body of bartik_preprocess_field(), it mostly uses 4 spaces instead of 2.
Comment #97
star-szrThis also needs a reroll, unassigning since it's been a while. Once rerolled we can work on the tweaks mentioned in #96.
@Nigel_S, if you want to work on the reroll and tweaks just reassign :) thanks!
Comment #98
InternetDevels CreditAttribution: InternetDevels commentedRe-rolling end fix with respect to comment #96
Comment #101
InternetDevels CreditAttribution: InternetDevels commentedThe reason for the failure became #732022: drupal_add_tabledrag() still using drupal_add_(js|library)(), should return array for #attached after the patch which drupal_add_tabledrab function was not valid. In this patch fixes bugs and made reroll.
Comment #103
Oleksandr Senenko CreditAttribution: Oleksandr Senenko commentedReroll
Comment #104
ipo4ka704 CreditAttribution: ipo4ka704 commented103: drupal-field_module_convert_theme_functions_to_twig-1987398-103.patch queued for re-testing.
Comment #106
InternetDevels CreditAttribution: InternetDevels commented#103 was stale, rerolled.
Comment #108
maggo CreditAttribution: maggo commented106: drupal-field_module_convert_theme_functions_to_twig-1987398-106.patch queued for re-testing.
Comment #109
joelpittetCouple little things and I'll do another round of manual testing.
This should say #type=>table. Just realized that. It may need to be re-worked to be a proper type table without #rows, but I'll leave that out of this conversion.
Can you remove this @todo. I'd rather not have that in with core.
Comment #110
star-szrComment #111
RainbowArrayHere's a revised patch with the suggested changes. I also fixed a deprecated function, element_children. Sorry if that's out of scope.
Comment #112
joelpittet@mdrummond Thanks for the revised patch! I'm fine with those changes, there is probably another issue outside this one dealing with it, which will cause that to be re-rolled or may be closed as duplicate, but same thing for String::checkPlain(). It's either this gets in first or it gets re-rolled.
Also love this, makes things much more useful in the template. No drupal_render_children() FTW!
Comment #113
star-szrTagging for #2094585: [policy, no patch] Core review bonus after reviewing #2072647: #theme 'maintenance_page' should support render arrays in #content.
Comment #114
thedavidmeister CreditAttribution: thedavidmeister commentedThis extra space below the "if" makes me feel weird in an OCD way. Can we remove it?
Is there a reason we no longer run #title through t()? I can see why required is not, as it's just a '*' character.
This looks like the conditional "inline" class would be broken now in the bartik template.
#2094585: [policy, no patch] Core review bonus for #2181507: Remove the deprecated usages of element_* methods.
Comment #115
star-szrTagging for reroll.
Comment #116
RainbowArrayHere's a reroll that also addresses the concerns raised in #114.
Comment #117
joelpittetSome nit picky notes:
This can likely be just
$variables['description'] = $element['#description'];
The condition doesn't help the statement any.
The Attribute order doesn't need to change here they were in the right order and Component\String should go before Xss.
Any chance we can do without the spaceless? I'd rather tweak the spaces in the tests if they fail.
Comment #118
LewisNyman116: drupal-field_module_convert_theme_functions_to_twig-1987398-116.patch queued for re-testing.
Comment #120
LewisNymanRerolled and addressed Joel's comments in 117.
Comment #121
rteijeiro CreditAttribution: rteijeiro commentedI checked @LewisNyman patch and works well. Just fixed some indentation and missing periods.
Comment #122
star-szrRolling in a very minor docs fix. I manually tested these templates again and looking good! Performance has been tested a couple times and shown to be quite comparable: #23 and #41. I think it's time for theme_field() to retire :)
When manually testing I noticed that to be consistent with theme_field() output we'd need to remove the
:
here but I think we should leave that to #1623574: Remove trailing space from form element labels and field labels (HTML nbsp) (or a follow-up issue from it) to clean up. See #1623574-50: Remove trailing space from form element labels and field labels (HTML nbsp) and after.Comment #123
webchickThis is just reformatting existing code, so not a commit-blocker. But I'm wondering why we don't move that <h4> and other associated markup to field-multiple-value-form.html.twig? Seems unfortunate to have to override a preprocess function in order to get at that, when everything else is so nicely "Twiggy."
Comment #124
webchickAccording to Cottser, this is because we're putting things in the format that #type table expects. Hm. Still seems unfortunate, but also seems to be the status quo, so...
Committed and pushed to 8.x. Thanks!
Comment #126
markhalliwellTo help further explain: it's used to wrap the title in the table header. I am guessing this was to get a desired font size and indicate some importance for this header. The table is rendered before being sent to the template and only provided as a single
{{ table }}
variable in the template to be printed. It is next to impossible to inject this small bit of markup in this particular template.I agree though, using #markup, #prefix and #suffix is definitely not the best approach or Best Practices™ anymore. A better approach would be to simply add a class for that header and then styling it via CSS if it needs to look "bigger" (similar to an h4).
FWIW, this was a "convert" issue. We can create a follow-up "consolidate/cleanup" issue for field.module if it is really warranted.
Comment #127
star-szrFollow-up: #2226233: Redo changes from field.module to Twig conversion issue that were clobbered