After some research I managed to answer my own question by implementing the hook_views_pre_view in my custom module. The method set_item is used to set the configuration of an item (field/sort/filter/etc) on a given display. The $print
variable bares the content to be rendered in the view header, it is just an example and it can be replaced by anything. Apparently now I can take advantage of the Drupal API or even set/unset any view item conditionally.
/**
* Implementation of hook_views_pre_view.
*/
function my_module_views_pre_view(&$view, &$display_id, &$args) {
$path = $_GET['q'];
// Construct the print link.
$print = l(t('Display a printer-friendly version of this page'), '/print/' . $path . '/print-friendly', array(
'attributes' => array(
'class' => array('print-friendly'),
'target' => '_blank',
'title'=> t('Display a printer-friendly version of this page.'),
),
)
);
if ($view->name == 'my_view_name' && $display_id == 'my_view_display') {
// View's header declaration.
$item = array(
'id' => 'area',
'table' => 'views',
'field' => 'area',
'relationship' => 'none',
'group_type' => 'group',
'ui_name' => '',
'label' => '',
'empty' => 0,
'content' => $print,
'format' => 'filtered_html',
'tokenize' => 0,
);
// Render the header.
$view->set_item($display_id, 'header', 'area', $item);
}
}