Using Views 3.
I have a view (a table) with another view (showing a map) associated on its header. This header view is a Global:view
I want the user to choose if wants to see both views (table and map) or only the table. I could do some javascript stuff hiding the map view, but the question is to improve performance (by just javascripting Drupal would have to do the job of getting the data for both views, even if user only selects to see the table view)
With an export of the main view, I can see this part related to the view on the header ('faunas_map')
/* Header: Global: View (Views field view) */
$handler->display->display_options['header']['view_field']['id'] = 'view_field';
$handler->display->display_options['header']['view_field']['table'] = 'views';
$handler->display->display_options['header']['view_field']['field'] = 'view_field';
$handler->display->display_options['header']['view_field']['label'] = 'test';
$handler->display->display_options['header']['view_field']['element_label_colon'] = FALSE;
$handler->display->display_options['header']['view_field']['view'] = 'faunas_view';
$handler->display->display_options['header']['view_field']['display'] = 'faunas_map';
$handler->display->display_options['defaults']['footer'] = FALSE;
I have tried to unset the header with a pre_build hook with differents, methods, check below
function views_testing_views_pre_build(&$view) {
//using kpr I see that $view->display['faunas_map'] does not exist anymore there, but the map view is plotted in case
unset($view->display['faunas_map']);
kpr($view);
Fatal error: Call to a member function get_option() on a non-object in /var/www/html/bopa/sites/all/modules/modules/views/includes/view.inc on line 1137
//using kpr I see that $view->display_handler->handlers['header'] does not exist anymore there, but the map view is plotted in case
unset($view->display_handler->handlers['header']);
Fatal error: Call to a member function get_option() on a non-object in /var/www/html/bopa/sites/all/modules/modules/views/includes/view.inc on line 1137
the code related to the fatal error on view.inc (line 1137) is as follows.
// Don't allow to use deactivated displays, but display them on the live preview.
if (!$this->display[$this->current_display]->handler->get_option('enabled') && empty($this->live_preview)) {
$this->build_info['fail'] = TRUE;
return FALSE;
}
Just for testing, uncommenting this code the error log disappears but the map view is plotted :.(
Some more testings I did so far in views_testing_views_pre_build(&$view)
unset($view->display['fauna_views']->display_options['header']);
unset($view->display['fauna_views']->handler->options['header']);
I get error Notice: Undefined property: views_display::$handler in view->execute() (line 1137 of /var/www/html/my_site/sites/all/modules/modules/views/includes/view.inc).
$header_item = $view->get_item('default', 'header', 'text');
$view->set_item_option('default', 'header', 'text', 'content', 'MY TEXT' . $header_item['content']);
Errors:
Notice: Undefined index: id in views_plugin_display->get_handlers() (line 935 of /var/www/html/bopa/sites/all/modules/modules/views/plugins/views_plugin_display.inc).
Notice: Undefined index: table in views_plugin_display->get_handlers() (line 960 of /var/www/html/my_site/sites/all/modules/modules/views/plugins/views_plugin_display.inc).
Notice: Undefined index: field in views_plugin_display->get_handlers() (line 960 of /var/www/html/my_site/sites/all/modules/modules/views/plugins/views_plugin_display.inc).
Notice: Undefined index: table in views_handler->init() (line 226 of /var/www/html/my_site/sites/all/modules/modules/views/includes/handlers.inc).