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:

  1. Setup a view to show fields.
  2. Copy views-view-fields.html.twig into bartik/templates (or your custom theme)
  3. 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.

Files: 
CommentFileSizeAuthor
#1 views-view-fields-2366167-1.patch5.05 KBManuel Garcia
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 75,083 pass(es), 2 fail(s), and 0 exception(s). View

Comments

Manuel Garcia’s picture

Status: Active » Needs review
FileSize
5.05 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 75,083 pass(es), 2 fail(s), and 0 exception(s). View

OK, 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

Status: Needs review » Needs work

The last submitted patch, 1: views-view-fields-2366167-1.patch, failed testing.

lauriii’s picture

Manuel Garcia’s picture

I 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.

lauriii’s picture

I think these 2 overlaps each other too heavily to split them. Can we talk more on IRC etc?

lauriii’s picture