Move classes out of the preprocess functions and into the Twig templates. Use the addClass() attribute method to add classes in the template. Use the clean_class filter to filter class names, if necessary. Maintain all existing functionality and ensure all existing class names are still in the markup, even ones that are inherited.
See the following issues for more detailed examples:
#2217731: Move field classes out of preprocess and into templates
#2254153: Move node classes out of preprocess and into templates
See this change record for information about using the addClass() method:
https://www.drupal.org/node/2315471
See this change record for more information about the phase 1 process of moving class from preprocess to templates:
https://www.drupal.org/node/2325067
Preprocess Functions Modified
template_preprocess_taxonomy_term
Twig Templates Modified
taxonomy-term.html.twig
Comment | File | Size | Author |
---|---|---|---|
#18 | move_taxonomy_term-2329775-18.patch | 1.65 KB | lauriii |
Comments
Comment #1
davidhernandezComment #2
lauriiiComment #3
lauriiiComment #4
ckrinaThe patch applies cleanly and the taxonomy terms mantain all the classes in the markup after it.
So moving it to RTBC.
Comment #5
lauriiiI added comment about the new variable
vocabulary_name
to twig.Comment #6
star-szrI don't have a strong objection but just curious why
term.bundle
wasn't used directly in the Twig template.Looks good though :)
Comment #7
lauriiiThat is true! I didn't notice that the term object is being passed for the template but its perfect!
Comment #8
RainbowArrayThis last patch lost the comment about the variable vocabulary_name.
Comment #9
RainbowArrayComment #10
lauriiiWe don't have it as a variable anymore because we are using
term.bundle
. Putting back to needs review.Comment #11
star-szrPerhaps out of scope (it was like this before…) but the attributes should probably be
|without('id')
otherwise we could end up with two ID attributes.And it could be cleaned up nicer with #2325517: Add methods for adding/removing attributes (not classes) on Attribute objects. Otherwise, looks great to me.
Comment #12
lauriiiThat is a good thing to fix. Now we cannot get double id attributes.
Comment #13
RainbowArrayAwesome. Great work laurii!
Comment #14
davidhernandezShould bundle be added to the comment under
term: The taxonomy term entity, including:
?Comment #15
RainbowArrayTerm bundle isn't something we're new we're adding with this patch. So not sure.
Comment #16
davidhernandezNo, not a new term, but I also wouldn't assume themers know what that means. I really only bring it up for completion sake, because the comment block has a term section. (Probably because term.id was already used.)
Comment #17
star-szrGood catch, let's add it.
Comment #18
lauriiiThat is a good catch! I would also assume that
term.bundle
isn't obvious for all of the themers.Comment #19
RainbowArrayLooks good.
Laurii, could you make sure to post interdiffs when you post patches? That makes it easier to see what has changed from patch to patch. Thanks for this fix!
Comment #20
lauriiiYeah sure! Just tought its a bit overhead for small patch like this :)
Comment #21
star-szrManually tested to confirm, the order of the classes changed and that's it.
Comment #22
alexpottCommitted cdad8d7 and pushed to 8.0.x. Thanks!