summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordamienmckenna2018-04-11 14:50:48 (GMT)
committerDamien McKenna2018-04-11 14:50:48 (GMT)
commit4c60cf4a26203c7ffb9b21441291d1039bb6ce09 (patch)
treeaa740e3cfc021b936d2f3435880985de681af1b4
parentdf56e74b663854fecd02333874fe3b6fd01d87c0 (diff)
Issue #2725131 by DamienMcKenna, boombatower, dasha_v: Rename hook_views_pre_view() because it doesn't work as described
-rw-r--r--includes/view.inc9
-rw-r--r--views.api.php23
2 files changed, 23 insertions, 9 deletions
diff --git a/includes/view.inc b/includes/view.inc
index ea9176a..a7c6ed2 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 feab443..e198396 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');
}