Hi,
I have created a custom module which sends rendered entities as full-text fields to Solr. These rendered entities contain HTML, which Solr gladly accepts, although I am not sure what this means for indexing, but these fields are just used for quickly showing rendered results from Solr using Apache Solr Views.
In the current version of the apachesolr_views_handler_field class, only the get_value() function has been implemented, which is fine for displaying RAW values, i.e. with no HTML. However, when the field contains HTML, it is being rendered as escaped HTML, rather than rendered HTML, which is not what I want nor expect.
I have tinkered some with the apachesolr_views_handler_field class, and I found that when I implement the render($values) function, using the exact same body as the get_value() function, the HTML renders properly. Non-HTML fields render just fine with the function implemented.
If you want, I can provide a patch.
Comment | File | Size | Author |
---|---|---|---|
#7 | views_field_render_when-2037877-7.patch | 1.08 KB | Robert Castelo |
#1 | apachesolr-add_render-2037877-1.patch | 885 bytes | afox |
Comments
Comment #1
afox CreditAttribution: afox commentedI faced with the same issue. Thanks for pointing to the render() -method. Attached is a patch we used to fix the issue. I just added XSS-sanitation to render which does the trick.
Comment #2
afox CreditAttribution: afox commentedComment #3
manarth CreditAttribution: manarth commentedSee also #1651386: HTML entities in Solr index being escaped again which has an alternative patch.
Comment #4
Martijn Houtman CreditAttribution: Martijn Houtman commentedI think the patch in #3 made it to the current -dev, and I don't think it solved my problem. The patch in #1 works for me.
Comment #5
yoavi CreditAttribution: yoavi commentedconfirm patch #1 works for me
thanks
Comment #6
MiroslavBanov CreditAttribution: MiroslavBanov commentedcheck_plain() is the default behavior for views field handlers. It is not correct to override this for all apachesolr_views field handlers. This may break existing implementations, and is not consistent with how database views work. See how the views module has a separate field handler specifically for this:
Comment #7
Robert Castelo CreditAttribution: Robert Castelo commentedHere's the patch from #1 but using filter_xss() instead of sanitize_value() so that we can include a few extra HTML tags:
'img', 'button', 'div', 'span', 'h2', 'h3', 'h4', 'article', 'br', 'p', 'table', 'tr', 'td'
Comment #8
nplowman CreditAttribution: nplowman at FFW commentedIf you are looking to do this without patching the original module, here is a solution that I pieced together based on an example in the Views Navigation module that will allow you to override the field handler on a case-by-case basis from a custom module.