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_toolbar
Twig Templates Modified
toolbar.html.twig
Comment | File | Size | Author |
---|---|---|---|
#5 | move_toolbar_classes-2329789-5.patch | 2.09 KB | lauriii |
Comments
Comment #1
davidhernandezComment #2
lauriiiComment #3
lauriiiI moved all the classes from
preprocess
but there's still some left in other functions. Should we handle those also in this issue?Comment #4
star-szr@lauriii what other functions?
Let's keep the inline class adding consistent please, passing multiple arguments to addClass rather than an array.
Comment #5
lauriiiFixed that for consistency. There is still classes added e.g. in
toolbar_toolbar()
Comment #6
lauriiiSending to testbot.
Comment #7
star-szrAh I see. I don't think we can mess with that too much, at least not in this issue. It looks like it is setting up individual toolbar items.
I re-reviewed and manually tested, this one looks good. Thanks @lauriii!
Comment #8
webchickCommitted and pushed to 8.x. Thanks!