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_table
Twig Templates Modified
table.html.twig
Comment | File | Size | Author |
---|---|---|---|
#40 | commit_all.jpg | 42.44 KB | lauriii |
#36 | 36-37-interdiff.txt | 3.36 KB | alexpott |
#36 | 2329767.37.patch | 5.74 KB | alexpott |
#35 | 2329767-36.patch | 4.35 KB | lauriii |
#35 | interdiff-2329767-32-36.txt | 2.51 KB | lauriii |
Comments
Comment #1
davidhernandezComment #2
lauriiiWhat should we do with classes that are coming from constants e.g.
RESPONSIVE_PRIORITY_MEDIUM
?Comment #3
star-szrHere's one option: http://twig.sensiolabs.org/doc/functions/constant.html
Comment #4
lauriiiThanks @Cottser! My question might have been irrelevant because after all I thought we might not even want to move those from preprocess to Twig. I applied my patch where all of the classes excluding responsive classes have been moved from preprocess to Twig.
Comment #6
star-szrI think we've been saying these should go in a set tag because they contain logic.
Comment #7
star-szrAnd cool that you didn't need to worry about those responsive classes! I guess that's probably something that should stay baked in anyway…
Comment #8
lauriiiCreated new patch which should pass the tests. Template was spitting empty class attributes which failed the tests.
Comment #9
davidhernandez@laurii, those ifs are not needed. We know about the empty class issue and that is being resolved here. #2330731: Attribute::addClass() adds empty class
Comment #10
lauriiiThanks @davidhernandez! That was very annoying problem! I uploaded new version of the patch and it most likely will fail the tests.
Comment #12
davidhernandez#2330731: Attribute::addClass() adds empty class has been committed.
Comment #14
star-szrComment #16
star-szrI think this one is blocked as well.
Comment #17
davidhernandez#2336355: Refactor Attribute rendering so that class="" is not printed is in.
Comment #19
lauriiiComment #20
mikl CreditAttribution: mikl commentedReviewed and tested, looks good to me :)
Comment #21
alexpottThe documentation in table.html.twig needs updating for the new variables.
Comment #22
lauriiiComment #23
sqndr CreditAttribution: sqndr commentedRemoving some of the tags. Found a typo in the documentation, updating the patch and added an interdiff.
Comment #24
SteffenRI just had a look at the patch and tested the whole thing with the latest DEV - looks fine for me.
Comment #31
lauriiiPutting back to RTBC
Comment #32
star-szrMinor docs tweak, was going to leave at RTBC, but…
I'm concerned we're losing this logic. Where has this been moved to?
Comment #33
star-szrNevermind, the footer is a separate part of the template :) back to RTBC.
Comment #34
alexpottMaybe it would be possible to not add these classes in a loop if we didn't add the empty message as a row in preprocess.
I think the variable name is
table_sort
. I think a better name might beactive_table_sort
.Comment #35
lauriiiComment #36
alexpottThere is still the row loop - we could something like this.
Comment #37
jamesquinton CreditAttribution: jamesquinton commentedLooks fine to me - no visual problems.
Empty row is spanning the correct number of columns and row attributes are correct.
Comment #38
catchDon't love not no_striping but not going to not commit this over the double negative.
Committed/pushed to 8.0.x, thanks!
Comment #40
lauriii