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_forums
template_preprocess_forum_icon
Twig Templates Modified
forums.html.twig
forum-icon.html.twig
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | move_forum_classes_from-2329769-10.patch | 2.38 KB | lauriii |
| #10 | interdiff-2329769-7-10.txt | 1.98 KB | lauriii |
Comments
Comment #1
davidhernandezComment #2
davidhernandezComment #3
mortendk commentedComment #4
mortendk commentedfixed the icon
needs some love for the table, think we should fix the tables first
Comment #5
rainbowarrayThis looks good. Think we'll need a .patch file for testbot to work?
The icon_status_class thing is kind of weird. We haven't had _class on the other variables we're passing to the template. That is how the variable is written in preprocess though I guess.
Comment #6
star-szrYeah it's a bit weird, icon_status_class is all built in preprocess and as it is doesn't need to go through clean_class either. But it's too complex for a ternary and it looks like we'd have to pass a ton of weird variables to the template to build the class entirely in the template.
Comment #7
lauriiiI changed
icon_status_classtoicon_statussinceicon_status_classdidn't make sense to me. I also removed clean_class from it.Comment #8
davidhernandezAre we excluding the forums change from this, or is there a good way to tackle that table code?
Comment #9
star-szrI don't think there is much we can do at this point about the table, there isn't really a template for it at this time.
While we're making this change why not just do $variables['icon_status'] directly, and get rid of the assignment at the end?
Maybe 'Indicates' instead of 'Points' here?
Comment #10
lauriiiI agree with @Cottser since there's no easy way to move classes from the table to templates since there isn't one.
Comment #11
miklLooks good to me.
Comment #12
alexpottCommitted a5d36ef and pushed to 8.0.x. Thanks!