Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Ilikejava on
I can't figure out why my code won't update the Views content used outside this function. It works fine inside, but has no effect when the field is referenced outside. I have tried using variable references (&$res, &$view), but it had no effect. Here is my code:
function mymodule_views_pre_render($view) {
foreach($view->result as $key => $res) {
if ($res->_field_data['nid']['entity']->type == "myentity") {
// do some stuff
$res->_field_data['nid']['entity']->field_myfield['und'][0]['value'] = "Blah";
drupal_set_message('<pre>' . "Test output: " . $res->_field_data['nid']['entity']->field_myfield['und'][0]['value'] . '</pre>');
}
}
}
It produces "Test output: Blah" like it is supposed to, but has no effect on the field when rendered in the View results.
Thanks.
Comments
I think you need to access
I think you need to access the field's rendered markup like this:
You also might find the Devel module really helpful.
You can easily look at the values like this:
http://www.radarearth.com