Posted by ben.hamelin on March 2, 2011 at 7:25pm
Hello!
I was wondering if anyone knew why there might be "missing" fields within the views result object. The specific field in question is the node "path" field. When previewing the view it of course is there. When I dump the results within my script it is not.
Here's some context:
I'm writing a custom script that will generate CSV data of blog nodes.
Within a PHP script, I have the following code:
$all_results_view = views_get_view("list_blog_entries");
$all_results_view->set_display("block_1");
$all_results_view->execute();
$all_results = $all_results_view->result;
foreach ($all_results as $r => $o)
{
$the_path = drupal_get_path_alias('node/'.$o->nid);
echo '"'.$o->nid.'","'.$o->node_title.'","'.$o->node_revisions_teaser.'","'.$o->node_data_field_employee_name_field_employee_name_value.'","'.$the_path.'","'.$o->node_created.'"';
echo "\r\n";
}
When I print_r the $o object, the path field is not included.
Does anyone know when and where the value for path (and presumably other) fields are defined?
Thanks!
bh
Comments
The $result object contains
The $result object contains fields actually in the database.
Fields that are derived (like the path) or fields that are pulled in via an additional query (such as lists of terms on a node, or lists of roles which use an additional query due to the many to one relationship) will not be in it. For those, you can look at the field handler, but that data will not be pulled in until pre_render() (this is when additional queries are run) or render() (for things like the node path).
Perfect, thanks for the
Perfect, thanks for the confirmation!
bh
http://www.adworkshop.com/
I'm having a similar
I'm having a similar difficulty - I'm using hook_views_pre_render() to process a view result, depending on complex combinations of a multi-value checkboxes in the node vs a date field in an optional referenced node - it's not possible to build the correct query for this in Views UI.
The multi-value checkbox field values are present in the view preview and themed output, but not yet present in hook_views_pre_render() $view->result. My module's weight is greater than views weight, if that makes any difference.
When and where does Views query and add data for a textfield of type "radio buttons / checkboxes" with multiple values enabled (checkboxes)? Not until render()?
I just want to confirm the data I need will not be available in pre_render() unless I query it myself or call $view->render().
Secondary queries
Anything that is retrieved through a secondary query is retrieved during the pre_render() phase. Where handlers store this is defined by the handler itself, but it's usually on the handler object. Conventionally most of the core Views handler store it in the 'items' variable on the handler but there's nothing that enforces this and I'm afraid I didn't do a good job of encouraging this so it doesn't always happen. So you can look at $view->field[$field_id] and see if your data is there.
That said once all handlers have rendered, their rendered output will all be in $view->style_plugin->rendered_fields[$row_id][$field_id].
Thanks for the clarification!
Thanks for the clarification!
Check fields permissions
Hi there!
Something alike happened to me,
While trying to re-arrange the results of a given view/display, some of the selected fields just did not get to the pre_render hook.
After a few hours of debugging, I've realized that those fields, were new or modified fields within the content-type, and didn't have the wright permissions set. So, when the fields handlers were initialized and access checked, these fields did not passed the validation.
Therefore, removed from the display config.
Hope this helps!!
--
Federico
I've spent a lot of time to
I've spent a lot of time to try to track down this bug - thank you for pointing me in the right direction!