I have a custom View defined in a module which provides a table display of data which takes a Node ID as an argument.
------------------
| Col 1 | Col 2 |
------------------
| A | B |
------------------
I want to be able to check some data from the node that is the argument to see if a certain field is set to either 0 (no extra column) or 1 (an extra column).
Using hook_views_default_views_alter()
I can add an extra column to the table using:
function MODULE_NAME_views_default_views_alter(&$views) {
if (isset($views['VIEW_NAME'])) {
// Add an extra field to the rider times view
$handler = &$views['VIEW_NAME']->display['default']->handler;
$handler->display->display_options['fields']['nothing']['id'] = 'nothing';
$handler->display->display_options['fields']['nothing']['table'] = 'views';
$handler->display->display_options['fields']['nothing']['field'] = 'nothing';
$handler->display->display_options['fields']['nothing']['label'] = '';
$handler->display->display_options['fields']['nothing']['alter']['text'] = 'Download';
$handler->display->display_options['fields']['nothing']['alter']['make_link'] = TRUE;
$handler->display->display_options['fields']['nothing']['alter']['path'] = 'download/[nid]/[number]';
$handler->display->display_options['fields']['nothing']['element_label_colon'] = FALSE;
}
}
But this adds the column to all the tables regardless of the argument.
I guess there should be a way to add the column through hook_views_pre_render()
but I can't figure out how.
The alternative would be to set up 2 views. One with the extra column and one without and conditionally show the correct view based on a Context/Panel visibility filter.