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_page
views_preprocess_page
bartik_preprocess_page
seven_preprocess_page
Twig Templates Modified
page.html.twig
bartik/templates/page.html.twig
seven/templates/page.html.twig
Comments
Comment #1
davidhernandezComment #2
mortendk CreditAttribution: mortendk commentedthe classes for the maintenance pages is only affected on the body tag - so i suggest we move that to html patch instead #2329753: Move html classes from preprocess to templates
i have updated the issue
Comment #3
davidhernandezDid you move them to the other issue?
Comment #4
mortendk CreditAttribution: mortendk commentedi moved the preprocesses listings over
Comment #5
davidhernandezComment #6
Sutharsan CreditAttribution: Sutharsan commentedComment #7
Sutharsan CreditAttribution: Sutharsan commentedviews_preprocess_page removes the 'contextual-region' body class if the page content is a view. This is a very specific case which I think should not be replaced with a removeClass() in the template.
bartik_preprocess_page and seven_preprocess_page pass body classes to the html template. A similar situation is discussed in #2329753: Move html classes from preprocess to templates.
I can not come up with a descent in-template alternative for adding classes to 'main_menu' and 'secondary_menu'.
Comment #8
davidhernandezI'm not seeing anything relevant here any more. Most of what we needed was changed in the html issue. preprocess_page isn't adding any classes.
Bartik and Seven are going through their own refactoring, so their changes can be worried about elsewhere. Also, Bartik and Seven changes don't affect core or Classy.