diff --git a/includes/view.inc b/includes/view.inc index ea9176a7c63ade746521d0a1fe5f615f384f04d0..a7c6ed217db0e21ea9cecd90b4941326bea09b13 100644 --- a/includes/view.inc +++ b/includes/view.inc @@ -1426,13 +1426,14 @@ class view extends views_db_object { $this->set_arguments($args); } - // Let modules modify the view just prior to executing it. - foreach (module_implements('views_pre_view') as $module) { - $function = $module . '_views_pre_view'; + // Trigger hook_views_pre_preview(). Allow other modules to modify the view + // just prior to executing the preview. + foreach (module_implements('views_pre_preview') as $module) { + $function = $module . '_views_pre_preview'; $function($this, $display_id, $this->args); } - // Allow hook_views_pre_view() to set the dom_id, then ensure it is set. + // Allow hook_views_pre_preview() to set the dom_id, then ensure it is set. $this->dom_id = !empty($this->dom_id) ? $this->dom_id : md5($this->name . REQUEST_TIME . rand()); // Allow the display handler to set up for execution. diff --git a/views.api.php b/views.api.php index feab443580168d3f418e3f30f3b55e69e96036c6..e19839619b5549d4357b5661925e31637ebc4bac 100644 --- a/views.api.php +++ b/views.api.php @@ -954,10 +954,23 @@ function hook_views_form_substitutions() { } /** - * Allows altering a view at the very beginning of views processing. + * Allows altering a view at the very beginning of processing a preview. * * Occurs before anything is done. * + * This hook is only triggered when the one of the following are invoked: + * - $view->execute_display() + * - $view->preview() + * + * As such code placed in this hook will not fire during: + * - $view->build() + * - $view->execute() + * - $view->render() + * + * Likely, hook_views_pre_build() or hook_views_pre_execute() are much better + * choices for most use cases since they are always invoked, not just when + * previewing a display. + * * Adding output to the view can be accomplished by placing text on * $view->attachment_before and $view->attachment_after. * @@ -968,15 +981,15 @@ function hook_views_form_substitutions() { * @param array $args * An array of arguments passed into the view. */ -function hook_views_pre_view(&$view, &$display_id, &$args) { +function hook_views_pre_preview(&$view, &$display_id, &$args) { // Change the display if the acting user has 'administer site configuration' // permission, to display something radically different. // (Note that this is not necessarily the best way to solve that task. Feel // free to contribute another example!) if ( - $view->name == 'my_special_view' && - user_access('administer site configuration') && - $display_id == 'public_display' + $view->name == 'my_special_view' + && user_access('administer site configuration') + && $display_id == 'public_display' ) { $view->set_display('private_display'); }