I'm having trouble setting header text dynamically in my custom views using the available hooks. I've seen others with similar issues (e.g. https://drupal.org/node/749452 + comments), but no concrete solution.
I can set fixed headers from hook_views_pre_view() (but NOT hook_views_pre_render()) like so:
$options = array(
'id' => 'area',
'table' => 'views',
'field' => 'area',
'empty' => FALSE,
'content' => $headertext,
'format' => 'filtered_html',
'tokenize' => 0,
);
$view->display_handler->set_option('header', array('text' => $options));
But what I really need is the same thing from hook_views_pre_render() (or similar) so that I can display stats on the number of results etc, data not available until after the query is executed. I could use the php filter via the GUI to do what I need, but I'm developing a module and don't want to force users allow that.
This worked from hook_views_pre_render():
$header_options = array(
'label' => t('Header text'), // Administrative label. Not really needed here.
'content' => $headertext, // Content of header text.
'format' => 'filtered_html', // Format of header text.
'empty' => 1, // Show even when there are no results. Set to zero otherwise.
);
$view->add_item('default', 'header', 'views', 'area', $header_options);
... but only for 'default'. Also, if I used default and just changed the text dynamically, other displays get messed up such that, for example, clicking on pager links in the child displays causes a reversion to the default.
It seems like I'm missing something obvious, any pointers?
Comments
Comment #1
Tony Stratton CreditAttribution: Tony Stratton commentedJust curious if any solution was found to this problem? I'm having the exact same issue. Thanks!
Comment #2
Tony Stratton CreditAttribution: Tony Stratton commentedI'm still curious.. but this appears to have worked within hook_views_pre_render():
Comment #3
pinin4fjords CreditAttribution: pinin4fjords commentedSorry I didn't see your replies earlier. I hadn't found a solution at all so I couldn't have helped you, but your solution works for me too - so thank you!
Comment #4
drasgardian CreditAttribution: drasgardian commentedThe solution from #2 doesn't appear to work when there are no results from the view.
Comment #5
spesic CreditAttribution: spesic commented@dragardian if you add a no results behavior to your view, it should work.
Comment #6
MustangGB CreditAttribution: MustangGB commented