Does anyone know a way to programmatically render a view from a module using the default theme after editing a node?
I'm basically trying to create a static html page of a view.
I have the following code in a custom module:
function MODULENAME_node_update($node) {
unset($node->is_new);
unset($node->original);
entity_get_controller('node')->resetCache(array($node->nid));
$view = views_get_view('references');
$view->set_display('block');
$output = $view->render();
file_put_contents('references.html', $output);
}
The code works but for obvious reasons it renders the view using the admin theme.
I have tried several things to no avail:
variable_set
function MODULENAME_node_update($node) {
variable_set('admin_theme', 'DEFAULT THEME HERE');
[...]
variable_set('admin_theme', 'ADMIN THEME HERE');
}
This hook is probably not the right place to switch themes as it is invoked too late for this.
global $custom_theme
function MODULENAME_node_update($node) {
global $custom_theme;
$custom_theme = 'DEFAULT THEME HERE';
[...]
$custom_theme = 'ADMIN THEME HERE';
}
custom menu item
function MODULE_NAME_menu(){
$items = array();
$items['outputview'] = array(
'title' => 'Test',
'type' => MENU_CALLBACK,
'page callback' => 'MODULE_NAME_output_view',
'access callback' => TRUE,
'theme callback' => 'DEFAULT THEME HERE'
);
return $items;
}
function MODULE_NAME_output_view() {
$view = views_get_view('references');
$view->set_display('block');
$output = $view->render();
file_put_contents('references.html', $output);
}
function MODULE_NAME_node_update($node) {
unset($node->is_new);
unset($node->original);
entity_get_controller('node')->resetCache(array($node->nid));
menu_execute_active_handler('outputview', FALSE); // or via curl
}
This works as the view gets rendered correctly but still uses the admin theme.
hook_custom_theme
function MODULENAME_custom_theme(){
return 'DEFAULT THEME HERE';
}