From 1004a87fbb83924c5ef762bb86c94d7faed9f14b Mon Sep 17 00:00:00 2001 From: webchick <webchick@24967.no-reply.drupal.org> Date: Mon, 2 Sep 2013 14:30:43 -0700 Subject: [PATCH] Issue #2073507 by grasmash: Fixed Parameters passed and documented incorrectly in Views hooks. --- .../views/lib/Drupal/views/ViewExecutable.php | 4 +-- core/modules/views/views.api.php | 26 +++++++++---------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/core/modules/views/lib/Drupal/views/ViewExecutable.php b/core/modules/views/lib/Drupal/views/ViewExecutable.php index f6ee1568ca78..0ce6a2c3d491 100644 --- a/core/modules/views/lib/Drupal/views/ViewExecutable.php +++ b/core/modules/views/lib/Drupal/views/ViewExecutable.php @@ -1357,7 +1357,7 @@ public function render($display_id = NULL) { } // Let modules modify the view output after it is rendered. - $module_handler->invokeAll('views_post_render', array($this, $this->display_handler->output, $cache)); + $module_handler->invokeAll('views_post_render', array($this, &$this->display_handler->output, $cache)); // Let the themes play too, because post render is a very themey thing. foreach ($GLOBALS['base_theme_info'] as $base) { @@ -1441,7 +1441,7 @@ public function preExecute($args = array()) { } // Let modules modify the view just prior to executing it. - \Drupal::moduleHandler()->invokeAll('views_pre_view', array($this, $display_id, $this->args)); + \Drupal::moduleHandler()->invokeAll('views_pre_view', array($this, $display_id, &$this->args)); // Allow hook_views_pre_view() to set the dom_id, then ensure it is set. $this->dom_id = !empty($this->dom_id) ? $this->dom_id : hash('sha256', $this->storage->id() . REQUEST_TIME . mt_rand()); diff --git a/core/modules/views/views.api.php b/core/modules/views/views.api.php index d57e28ee1bc9..226f92f1eb3f 100644 --- a/core/modules/views/views.api.php +++ b/core/modules/views/views.api.php @@ -371,13 +371,11 @@ function hook_views_form_substitutions() { * * @see \Drupal\views\ViewExecutable */ -function hook_views_pre_view(ViewExecutable &$view, &$display_id, array &$args) { - // Change the display if the acting user has 'administer site configuration' - // permission, to display something radically different. - // @todo Note that this is not necessarily the best way to solve that task. - // Add a better example. - if ($view->name == 'my_special_view' && user_access('administer site configuration') && $display_id == 'public_display') { - $display_id = 'private_display'; +function hook_views_pre_view(ViewExecutable $view, $display_id, array &$args) { + + // Modify contextual filters for my_special_view if user has 'my special permission'. + if ($view->name == 'my_special_view' && user_access('my special permission')) { + $args[0] = 'custom value'; } } @@ -392,7 +390,7 @@ function hook_views_pre_view(ViewExecutable &$view, &$display_id, array &$args) * * @see \Drupal\views\ViewExecutable */ -function hook_views_pre_build(ViewExecutable &$view) { +function hook_views_pre_build(ViewExecutable $view) { // Because of some unexplicable business logic, we should remove all // attachments from all views on Mondays. // (This alter could be done later in the execution process as well.) @@ -413,7 +411,7 @@ function hook_views_pre_build(ViewExecutable &$view) { * * @see \Drupal\views\ViewExecutable */ -function hook_views_post_build(ViewExecutable &$view) { +function hook_views_post_build(ViewExecutable $view) { // If the exposed field 'type' is set, hide the column containing the content // type. (Note that this is a solution for a particular view, and makes // assumptions about both exposed filter settings and the fields in the view. @@ -438,7 +436,7 @@ function hook_views_post_build(ViewExecutable &$view) { * * @see \Drupal\views\ViewExecutable */ -function hook_views_pre_execute(ViewExecutable &$view) { +function hook_views_pre_execute(ViewExecutable $view) { // Whenever a view queries more than two tables, show a message that notifies // view administrators that the query might be heavy. // (This action could be performed later in the execution process, but not @@ -462,7 +460,7 @@ function hook_views_pre_execute(ViewExecutable &$view) { * * @see \Drupal\views\ViewExecutable */ -function hook_views_post_execute(ViewExecutable &$view) { +function hook_views_post_execute(ViewExecutable $view) { // If there are more than 100 results, show a message that encourages the user // to change the filter settings. // (This action could be performed later in the execution process, but not @@ -487,7 +485,7 @@ function hook_views_post_execute(ViewExecutable &$view) { * * @see \Drupal\views\ViewExecutable */ -function hook_views_pre_render(ViewExecutable &$view) { +function hook_views_pre_render(ViewExecutable $view) { // Scramble the order of the rows shown on this result page. // Note that this could be done earlier, but not later in the view execution // process. @@ -524,7 +522,7 @@ function hook_views_pre_render(ViewExecutable &$view) { * * @see \Drupal\views\ViewExecutable */ -function hook_views_post_render(ViewExecutable &$view, &$output, CacheBackendInterface &$cache) { +function hook_views_post_render(ViewExecutable $view, &$output, CacheBackendInterface $cache) { // When using full pager, disable any time-based caching if there are fewer // than 10 results. if ($view->pager instanceof Drupal\views\Plugin\views\pager\Full && $cache instanceof Drupal\views\Plugin\views\cache\Time && count($view->result) < 10) { @@ -544,7 +542,7 @@ function hook_views_post_render(ViewExecutable &$view, &$output, CacheBackendInt * @see hook_views_query_substitutions() * @see \Drupal\views\Plugin\views\query\Sql */ -function hook_views_query_alter(ViewExecutable &$view, QueryPluginBase &$query) { +function hook_views_query_alter(ViewExecutable $view, QueryPluginBase $query) { // (Example assuming a view with an exposed filter on node title.) // If the input for the title filter is a positive integer, filter against // node ID instead of node title. -- GitLab