Problem
This is a bug found while tackling #2348747: Convert theme_views_view_fields() to 100% Twig: remove the theme function
All the HTML is escaped coming out of core/modules/views/templates/views-view-fields.html.twig
due to twig autoescaping template files.
Steps to see this in action:
- Setup a view to show fields.
- Copy views-view-fields.html.twig into bartik/templates (or your custom theme)
- Clear cache
Status
The file is basically unusable by themes.
Workaround: print out everything using the |raw
twig filter. Not the best solution.
Quoting from comment #3 on #2348747:
OK, so after some chat with dawehner in IRC, This is what has been tried:
- Removed String::checkPlain() calls from FieldPluginBase::elementType(), FieldPluginBase::elementLabelType() and FieldPluginBase::elementWrapperType() -> core/modules/views/src/Plugin/views/field/FieldPluginBase.php.
- Removed String::checkPlain call on the label inside the template_preprocess_views_view_fields function in core/modules/views/views.theme.inc.
These changes did NOT have an effect apparently.
Comment | File | Size | Author |
---|---|---|---|
#1 | views-view-fields-2366167-1.patch | 5.05 KB | Manuel Garcia |
Comments
Comment #1
Manuel Garcia CreditAttribution: Manuel Garcia commentedOK, here is a proposed solution, which is to move the generation of the dynamic markup out of the preprocess function and into the twig file & theme function.
This way the file will print the proper markup, and we only have to use the
|raw
filter on the attributes.Find attached the patch doing this. Note that I've updated the theme_ function also so that we don't break anything in this change, but it will be removed on the parent issue #2348747: Convert theme_views_view_fields() to 100% Twig: remove the theme function
Comment #3
lauriiiIsnt this duplicate to #2348747: Convert theme_views_view_fields() to 100% Twig: remove the theme function?
Comment #4
Manuel Garcia CreditAttribution: Manuel Garcia commentedI split these into two issues in order to make reviewer/commiter's lives easier ;)
This one handles the bug in core, the other one gets rid of the theme function.
Comment #5
lauriiiI think these 2 overlaps each other too heavily to split them. Can we talk more on IRC etc?
Comment #6
lauriii#2348747: Convert theme_views_view_fields() to 100% Twig: remove the theme function