In a view I need to add a custom data-attribute to the row output (just like classes are added). Simply rewriting the output doesn't work because XSS attribute filtering strips the attribute. How can I accomplish this in a reasonable way? These answers are for D7 and do not quite cover dynamic output:
-
1How are you trying to Rewrite, with what code? I haven't noticed any stripping of the attribute, maybe it's only your value missing?– prkosCommented May 7, 2019 at 21:59
-
Oh man, you are right, it was a missing value! When things didn't work, I started research, found out that the style attribute is stripped in views when rewriting and stumbled upon drupal.org/project/views/issues/417956 – so I concluded, the attribute is stripped as well. Thanks!– Madam AdamCommented May 8, 2019 at 8:16
1 Answer
To summarize for future reference:
You can add data attributes using Rewrite in Views Fields.
If you added a custom data-attribute but something isn't working, the problem might be in the value ;)
What gets stripped by the filter_xss_admin()
on Rewrite is most notably the <object>
tag and style=""
attribute because users can submit malicious code through those.
It seems Views for D7 will have that check removed in the next release: Remove filter_xss_admin() from result rewriting because views editors are already trusted admins