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_views_ui_display_tab_setting
template_preprocess_views_ui_display_tab_bucket
template_preprocess_views_ui_view_info
template_preprocess_views_ui_view_preview_section
Twig Templates Modified
views-ui-display-tab-setting.html.twig
views-ui-display-tab-bucket.html.twig
views-ui-view-info.html.twig
views-ui-view-preview-section.html.twig
Comment | File | Size | Author |
---|---|---|---|
#28 | 2329919-28.patch | 4.07 KB | lauriii |
#28 | interdiff-2329919-23-28.txt | 1.5 KB | lauriii |
Comments
Comment #1
davidhernandezComment #2
lanchez CreditAttribution: lanchez commentedComment #3
lanchez CreditAttribution: lanchez commentedHere's a patch. TBH only template_preprocess_views_ui_display_tab_setting and template_preprocess_views_ui_display_tab_bucket needed this kind of love.
Comment #4
RainbowArrayThis is looking good to me. See what testbot says.
Comment #5
star-szrMakes sense, looks good. Thanks @lanchez!
Comment #6
davidhernandezJust confirming the others are erroneous and striking them out of the summary.
Comment #7
star-szrManually tested at /admin/structure/views/view/content also, looks great. Absolutely no changes.
Comment #8
dawehner+1
Comment #9
alexpottWhy not just use element.name and element.overridden instead of added new variables?
element.overridden instead?
Comment #10
star-szr@alexpott the short answer is because we haven't solved #2160611: Provide {{ item.item.alt }} Twig syntax for getting data from $item['#item']['alt']. But we could use the square bracket syntax here I suppose.
Comment #11
star-szrHere's what that would look like. What do we think?
Comment #12
RainbowArrayDo we use the square bracket syntax elsewhere? It feels somewhat odd.
Comment #13
star-szrI agree, I'm not a fan. I don't think we use it anywhere else in core at this time.
Comment #14
dawehnerWell, I know that several people now uses short array syntax for every new line of code, but yeah we agreed that there should be no requirement
to use it.
Comment #15
dawehnerLooks nice!
Comment #16
lauriiiUnassigning :)
Comment #17
star-szr@dawehner I don't mean the short array syntax in PHP, I'm totally fine with that. It's the
var['key']
syntax in Twig that I'm not a fan of but we need to use that to access hashed keys.Comment #18
webchickShooting back over to Alex.
Comment #19
RainbowArrayIn #2229435: Clean up the way attributes are printed in field.html.twig, there was a decision to avoid using the bracket octothorpe syntax as a template variable. I think we need to clarify if we want to make the same call on this issue before it gets in. Adding an extra variable just to avoid syntax weirdness may feel like overkill, yes, but it also makes it easier to explain how to work with variables in templates to new folk.
Comment #20
lauriiiComment #22
RainbowArrayBefore, we were checking if the keys #name and #overridden existed before adding the classes. My guess is we need to do something similar in preprocess: default the variables to be empty, and content if the element keys exist?
Comment #23
lauriiiComment #25
lauriiiComment #26
rteijeiro CreditAttribution: rteijeiro commentedLooks good!
Comment #27
alexpottThese variables are not documented.
Comment #28
lauriiiComment #29
davidhernandezWhat is the difference between the title and name of the bucket? The documentation uses the same examples.
Comment #30
lauriiiOnly difference I found between title and name is that title is optional and name is mandatory
Comment #31
LewisNymanIt seems like the issues raised by Alex have been addressed. A quick manual test does not show any visual regressions. Good work all!
Comment #32
alexpottCommitted 4722170 and pushed to 8.0.x. Thanks!