Issue #1898460 by pixelmord, bstoppel, steveoliver, jenlampton, johnnygamba, jastraat, Cottser, lbainbridge, myke, thedavidmeister, c4rl, joelpittet, ezeedub: Convert taxonomy module to Twig.
(as of #58)
Task
Convert PHPTemplate templates to Twig templates
Remaining
- Manual testing (see below)
| Template path | Conversion status |
|---|---|
| theme_taxonomy_overview_terms | Will be converted in #type table issue: #1938932: Remove taxonomy_overview_terms() and taxonomy_overview_vocabularies() theme functions in favour of table #type |
| theme_taxonomy_overview_vocabularies | Will be converted in #type table issue: #1938932: Remove taxonomy_overview_terms() and taxonomy_overview_vocabularies() theme functions in favour of table #type |
| core/modules/taxonomy/templates/taxonomy-term.tpl.php | converted |
To test this code...
1) create a vocabulary
2) add a term (name and description please)
3) navigate to the term page (taxonomy/term/1)
4) confirm that the term at the top of the page is being rendered through taxonomy-term.html.twig
Unable to fully test without #1881606: Use a derivative to integrate all entities as row plugins
Related
#1757550: [Meta] Convert core theme functions to Twig templates
#1938932: Remove taxonomy_overview_terms() and taxonomy_overview_vocabularies() theme functions in favour of table #type
#1987510: [meta] Convert all core *.tpl.php templates to Twig as singular patch
| Comment | File | Size | Author |
|---|---|---|---|
| #54 | 1898460-54-twig-taxonomy-php-tpls.patch | 5.28 KB | joelpittet |
| #54 | interdiff.txt | 1.13 KB | joelpittet |
| #49 | 1898460-49.patch | 6.04 KB | star-szr |
| #42 | 1898460-42.patch | 5.91 KB | star-szr |
| #42 | interdiff.txt | 1.84 KB | star-szr |
Comments
Comment #1
c4rl commentedTagging
Comment #2
steveoliver commentedFrom sandbox issue: #1760990: Twig: convert core/modules/taxonomy/taxonomy-term.tpl.php
commit attribution goes to pixelmord and bstoppel
Comment #3
star-szrThis looks good to me, just rolling a new patch to fix the @see references. The missing parens for these have now been fixed in the Twig sandbox.
Can this be "Preprocess variables for taxonomy-term.html.twig.", or is there a reason for referring to multiple templates?
Comment #4
jenlamptonWe decided not to refer to the template by file name so that the preprocess function would not be Twig-specific, and could also be used for the PHPTemplate sticklers. I agree though, that it should not be plural. How about:
Preprocess variables for the taxonomy term template.That seems more appropriate.Comment #5
fabianx commentedThis looks very close to RTBC to me.
I would just mention that we sneak'ed in a change from $label -> $term_name. ;-)
Leaving for others to review, then RTBC.
Comment #6
jenlamptonA few more changes:
- updated preprocess docs to match new standards
- removed references to render_var and PHP variables in twig template docs
- removed references to data types in twig template docs
- double checked list of available variables in template - and corrected
- printed title_attributes and content_attributes in the template, so that if someone adds any ever, they will work.
- changed the variable name to
urlfrom term_url- changed the variable name back to
title(from name/label) for consistency with other templates, and title_prefix and title_suffix- also printed title_prefix and title_suffix.
I'd also like to add that there is no where in core where we can see a taxonomy term full view mode that's not the term listing page (yet). I tested a patch at [#1881606 ] to see if I could use views to see one, but no luck yet. This will work for now, but we should retest after we can see term entities elsewhere.
Comment #6.0
jenlamptonAdd commit message to summary
Comment #6.1
jenlamptonadd steps to test
Comment #6.2
jenlamptonadded related
Comment #7
Anonymous (not verified) commentedTesting with Sagetree team on Twig sprint weekend of 3-9-13, the patch seems to work. Applied patch, created vocabs + terms, got expected results.
Comment #8
jenlamptonThanks @eamen, can you (or someone else) try the patch at #1881606: Use a derivative to integrate all entities as row plugins and see if we can get a taxonomy term to appear someplace other than on the taxonomy/term/N page, so we can test that template output too?
Once that is done (and if it works) please change the status to RTBC!
Comment #8.0
jenlamptonTweaking commit message
Comment #9
joelpittetTried that #1881606, couldn't get past the views taxonomy term edit screen, posted a bug. Your twig conversion looks good except for a very minor trailing whitespace. (if you are using Sublime Text Editor, enable the TrailingSpaces Package, it's amazing:)
Noticed the form tables aren't in here, that's a good way to go. Here is the related #type=>table conversion for those if anybody is looking:
#1938932: Remove taxonomy_overview_terms() and taxonomy_overview_vocabularies() theme functions in favour of table #type
Comment #9.0
joelpittetblocked
Comment #9.1
star-szrAdd conversion summary table
Comment #9.2
star-szrLinkify, update blocker
Comment #10
jastraat commentedThe twig coding standards indicate that there should not be an "other variables" section: http://drupal.org/node/1823416
Comment #11
star-szr@jastraat - great catch! Feel free to reroll with that update and remove the trailing whitespace here:
Comment #12
jastraat commentedRe-rolled with changes from #11.
Comment #13
star-szrI diffed the two patches, changes look good. Thanks @jastraat!
Comment #14
star-szrThis is looking really good, thanks everyone. Found some minor documentation tweaks and then I think this is ready to go:
Per #1913208: [policy] Standardize template preprocess function documentation this should end in "templates", so maybe:
Prepares variables for taxonomy term templates.
I think this should say "taxonomy term", even though the .tpl.php didn't.
URL is an acronym so should be all caps.
The second level should be indented by one more space to line up with "It includes…"
I think we can probably leave out is_admin, is_front, and logged_in since those are available to every template, see _template_preprocess_default_variables().
Comment #15
star-szrOops, status.
Comment #16
johnnygamba commentedi will take it.
Comment #17
johnnygamba commentedDocumentation tweaks recommended on comment #14 done.
Comment #18
star-szrChanges look good, two minor nitpicks:
We should remove the word "the" now that it's plural.
The first line here is too long (actually, it was too long before as well but I didn't notice). Please wrap "to." onto the next line.Edit: The phrasing is awkward anyway, how about "The vocabulary that this term belongs to." - then no need to wrap :)
Comment #19
johnnygamba commentedDocumentation tweaks recommended on comment #18 done.
Comment #21
johnnygamba commentedPatch #19 fixed.
Comment #21.0
johnnygamba commentedUpdate blocker again
Comment #22
star-szrI just manually tested the patch again, works well. I also compared output when removing the if statement from both the Twig and PHPTemplate files to make sure the linked title was output consistently.
If we can just remove this extra line added in taxonomy_term_view_multiple(), I'd say this is ready to go!
Comment #23
johnnygamba commentedtweaks recommended on comment #22 done.
Comment #24
star-szrThanks @johnnygamba! After reviewing again I found another small update:
I didn't notice these before, let's remove these 3 lines from the preprocess docblock. These variables are not passed in from the calling code, rather they are added in template_preprocess().
Comment #25
johnnygamba commentedHi @Cottser, no problem, here it is.
Comment #26
star-szrThanks again @johnnygamba. I looked over this thoroughly and found one more bit of documentation that's a bit confusing and can be improved, this is in the preprocess function:
The wording here is confusing and I think we should be more clear about what this variable is and what it contains. Something like this could work:
Comment #27
myke commentedMade the changes recommended in #26.
Comment #28
star-szr@myke - thank you! The changes look good, but taxonomy-term.html.twig is missing from your patch.
Comment #29
lbainbridge commentedI have rerolled the above patch to include taxonomy-term.html.twig and new documentation. Also removed a few references to zebra and id variables in the documentation as per #1968322: Remove unused $id and $zebra variables from templates hence my interdiff relates to that change.
Comment #29.0
lbainbridge commentedUpdate commit message
Comment #30
berdirIs there a reason for this change?
I'm not sure if it's official but I thought that we're usually not doing multiple assignments on a single line like this...
Hm, this was discussed before in another issue and possibly also here. The thing is that all entities now have a label. And terms have a name. But neither terms nor entities in general have a "title". So I'm not sure this makes sense to rename, at least not in such an issue that should just convert and not actually change things like this?
What about user.tpl.php, for example? Users also have a name and not a title (a title in that context would IMHO be something totally different).
Comment #31
star-szr@Berdir, after giving it some thought I actually agree with you on both points. Let's leave those both alone for now in this conversion.
Comment #31.0
star-szrAdd API changes section for our variable tweak
Comment #31.1
star-szrRemove API changes
Comment #32
star-szrImplemented feedback from #30. This patch also removes title_prefix, title_suffix, title_attributes, and content_attributes from the Twig template since they weren't in the PHPTemplate version at all. If someone can explain their inclusion here we can roll this back.
Comment #33
shawn dearmond commentedI'll test it
Comment #34
shawn dearmond commentedOops, my bad. Thought you were still looking for manual testers.
Comment #35
star-szrRemoved title_prefix and title_suffix docs from the preprocess as well. These are standard variables but aren't used in this preprocess/template - see _template_preprocess_default_variables().
Comment #36
jenlamptonThis is the theme layer, and most people who are building things here will see two things, 1) the Drupal user interface (which does not call any of these things a label) and 2) the code in the template file. The names of things in those two places need to match in all cases.
If someone changes the User Interface so the title on a node, a term, or a user becomes a "label", at that point we can talk about changing the variable name in the matching template file. If we keep coming up with arbitrary names for things that people won't recognize and can't relate to anything they've already seen then Drupal continues to be a huge WTF.
In preprocess (where we are using PHP, and we can expect that people will know what an entity is, and that a node, a user, a term, etc is actually one of these things) we can use the weird-drupal-entity-language, and wrap it nicely in a name that makes sense to people in templates.
Looking at the term UI, the correct name for the variable here is Name. I'll reroll to reflect that change.
Comment #37
jenlamptonokay, attached patch renames title/label to name, adds a comment that says why, removes some whitespace (linebreaks) in the template, and removes one line from the docblock in the template file (since globally added vars don't need to be defined in every template).
Giving her another go!
Comment #37.0
jenlamptonUpdate commit message
Comment #38
thedavidmeister commented+ * - taxonomy-term: The current template type, i.e., "theming hook".Don't need a comma after i.e.
This explanation seems to be mixing the concepts of a human readable name "Tag" with what is implied to be the machine name "tag" - in general though there could be a lot of differences beyond capitalisation between the human/machine names for a vocabulary.
+ * - term: Full term object."object" is a PHP data type so we shouldn't use it in Twig templates, unless we're using "object" to mean something else in a Twig template?
This is different to the way we're documenting properties of variables in Twig templates elsewhere, normally we just have an indented list of the available properties. Obviously this will be dynamic in this case, since they're fields that are configured per-vocab so it isn't so easy to just come up with a list but it's not clear to me from the docs how you'd access the "description".
I also noticed that while there are manual testing steps in the summary (amazing!) there is no tag for manual testing on the issue, so we need somebody to apply the patch, follow the steps and post the before/after markup.
Comment #39
c4rl commentedNeeded re-roll due to #1818560: Convert taxonomy entities to the new Entity Field API getting committed.
We've used "entity" elsewhere, let's do that. (This actually brings up a larger documentation issue in Drupal whether we should refer to entity objects as "entities" or "objects" in documentation. Not sure there's an issue to resolve this, so I'll file one if I don't find one.)
We do the same thing in node.html.twig, see #1898432-79: node.module - Convert PHPTemplate templates to Twig.
What is meant by "Direct URL" as opposed to "URL?"
Weird sentence here; word "includes" is twice. How about instead: "attributes: HTML attributes for the wrapper. Class attribute includes:" etc.
Comment #40
star-szrI'll work on the reroll and tweaks.
Comment #41
star-szrFirst the reroll.
Comment #42
star-szrThis should address most of #38 and #39 and I made a couple other docs tweaks. Feedback welcome :)
I compared the markup on the taxonomy term page via visual diff and DaisyDiff, it matches exactly.
Comment #43
star-szrSo you don't have to take my word for it:
Before:
After:
Comment #44
fabianx commented#42: 1898460-42.patch queued for re-testing.
Comment #46
joelpittet#42: 1898460-42.patch queued for re-testing.
Comment #48
star-szrI will reroll.
Comment #49
star-szrRerolled for #1966704: In-place editing for taxonomy terms and custom blocks (added title_prefix and title_suffix in the taxonomy-term template).
Comment #49.0
star-szrrm sand
Comment #50
c4rl commentedPer #1757550-44: [Meta] Convert core theme functions to Twig templates, retitling to indicate this issue applies to templates rather than theme_ functions (though there are no theme_ functions in this module).
Comment #50.0
c4rl commentedUpdated issue summary.
Comment #51
gnugetI will provide a patch with only the .tpl.php conversions
Comment #52
gnugeteh.. seems to this module only has tpl.php templates then there is nothing to do here :-p
Comment #53
star-szrInstantiating the Attribute object in preprocess is not needed now that #1982024: Lazy-load Attribute objects later in the rendering process only if needed is in, so we should remove both of these lines.
Comment #54
joelpittet#53 done
Comment #55
star-szrTagging for profiling.
Comment #56
ezeedub commentedScenario: Using Stark, devel generate 1 term, 100 articles, and set site front page to taxonomy/term/. Comparing 8.x (3b1f85aa3) to #54.
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=5199baba8e9fa&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=5199baba8e9fa&...
Comment #57
joelpittetNice work, thanks Ed!
Comment #58
alexpott+1. Ready for #1987510: [meta] Convert all core *.tpl.php templates to Twig as singular patch
Comment #58.0
alexpottRevise summary
Comment #59
alexpottCommitted 8f7dc88 and pushed to 8.x. Thanks!
Comment #60.0
(not verified) commentedUpdated commit message