[ Issue overview ]-------------------------------------------------------------
Overview: I am trying to create a few custom fields that are indexed in solr and are viewable in views. Recently I was able to accomplish this with ease using views 7.x-3.0-rc3 and search_api at 7.x-1.0-beta10, and entity at 7.x-1.0-beta10, however after upgrading to the latest code for these modules the views displays for my custom fields ceased to function. The latest release of these modules is required for FacetApi + SearchAPI at the soon to be released iVillage.com (restructuring).
The definition of the entity property info alter looks like this:
It's purpose is to provide fully ready to view image <img /> tags to output in solr based views.
function ivillage_search_entity_property_info_alter(&$info) {
// 120x90thumb preset
$info['node']['properties']['promo_120x90thumb_img'] = array(
'type' => 'text',
'label' => t('Promotional image: 120x90thumb'),
'sanitized' => FALSE,
'getter callback' => 'ivillage_search_promo_120x90thumb_img_getter_callback',
);
// 133x99thumb preset
...another of the same type
}
I did a full trace of the issue and found that there were actually a couple related issues causing the custom fields to return empty:
[ Issue 1. ]-------------------------------------------------------------------
get_value($handler, $values, $fields = NULL, $default = NULL) is not returning data as written. [ref. entity_views_field_handler_helper.inc ln 297]
I found that $default is never set when determining the value for the field: promo_120x90thumb_img in this case.
To remedy this situation I added a line to get_value() in entity_views_field_handler_helper.inc on line 324:
It looks like this:
if ($field === 'entity object') {
$values->_entity_properties[$selector] = $wrapper->value();
}
else {
+ $default = (isset($default)) ? $default : $selector; // new line (324)
$values->_entity_properties[$selector] = isset($wrapper->$field) ? $wrapper->$field->value(array('identifier' => TRUE)) : $default;
}
If this is not done $values->_entity_properties[$selector] is empty on return from get_value. Once the aforementioned line is added, the data returned to $values->_entity_properties[$selector] is a-ok.
[ Issue 2. ]-------------------------------------------------------------------
2. render_single_value($value, $type = NULL) ignores the fact that sanitized => FALSE for this field. [entity_views_handler_field_text.inc ln. 95]**
Here is an example of what data should be returned:
<img src="http://local.ivillage.com/sites/default/files/styles/120x90thumb/public/content/promo_image/imagefield_ngf5ZQ.png" width="120" height="90" alt="" />
Currently entity 7.x-1.0-rc1 returns '' for this field after render_single_value calls
$this->sanitize_value($value, 'xss'); I looked all over in the data available in $this and $values to implement a quick fix, and maybe I missed it but I don't see any settings in $this that reflect that sanitize should not be run. I would have given a proposed fix if I could.
I have a plan of how I can get around the xss filter bit. It's ugly but I could simply chop off the '<' and '>' from the $img in the getter function and then simply replace them in a views field tpl. I would feel real bad/dirty about doing this but I would do it if I have to. (I tried re-writing the view but views filtered the angle brackets...)
** render_single_value is called by another render_single_value($handler, $value, $values). [entity_views_field_handler_helper.inc ln. 481] My thoughts were that this is an optimal area to decide if and how the field is to be filtered.
-------------------------------------------------------------------------------
Thank you for this great module set! And also thanks for reading the short version of this issue report (yeah I have a long one ;-). If you need a more detailed description of the issue or if you have any questions, comments, or suggestions please advise: I can provide a step by step guide of the chain of processing that is taking place and commentary regarding the status at each of the steps to help resolve this issue.
Warm regards, Derek Webb
Comments
Comment #1
fago