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_filter_guidelines
template_preprocess_text_format_wrapper
template_preprocess_filter_tips
Twig Templates Modified
filter-guidelines.html.twig
text-format-wrapper.html.twig
filter-tips.html.twig
Comment | File | Size | Author |
---|---|---|---|
#11 | interdiff.txt | 1.88 KB | star-szr |
#11 | 2329837-11.patch | 4.8 KB | star-szr |
#7 | interdiff.txt | 504 bytes | star-szr |
#7 | 2329837-7.patch | 4.79 KB | star-szr |
#5 | interdiff.txt | 1.08 KB | star-szr |
Comments
Comment #1
davidhernandezComment #2
star-szrGoing to try this one.
Comment #3
star-szrThis is going to be blocked on #2330731: Attribute::addClass() adds empty class because there are single classes added with a ternary. But other than that, reviews please!
I used the |replace filter in filter-tips.html.twig to preserve the pre-patch classes which contain underscores (can be seen by navigating to /filter/tips).
Comment #4
davidhernandezWhy use wrapper_classes on tip and tip_classes on item? Wouldn't tip_classes, item_classes be better? Also, on using description_class, is the aria attribute accessible at the template?
Comment #5
star-szrThanks for the review! The aria-describedby gets unset, so it's not accessible through the template. tip_classes and item_classes does make a lot more sense, here's that.
Comment #6
davidhernandezWe don't need this line in template_preprocess_filter_tips since long is no longer checked in preprocess, correct?
$long = $variables['long'];
Otherwise, everything works fine. I manually tested and saw all the same classes before and after.
Comment #7
star-szrNice catch, thanks @davidhernandez!
Comment #8
davidhernandezComment #9
alexpottDo we need
description_class
- can't we just check ifattributes.aria-describedby
is set in the twig template?Comment #10
star-szrIt's not available in the template because it is unset after being checked in the preprocess. It's basically being moved to the ID attribute. Here is the issue: #2126761: The body field summary textarea indicates it has a description with aria-describedby attribute, but the DOM id value points to a non-existent node.
Comment #11
star-szrBetter variable name c/o @alexpott :)
Comment #12
alexpottCommitted 364c388 and pushed to 8.0.x. Thanks!