W3cubDocs

/Drupal 8

function hook_views_pre_build

hook_views_pre_build(ViewExecutable $view)

Act on the view before the query is built, but after displays are attached.

Output can be added to the view by setting $view->attachment_before and $view->attachment_after.

Parameters

\Drupal\views\ViewExecutable $view: The view object about to be processed.

See also

\Drupal\views\ViewExecutable

Related topics

Hooks
Define functions that alter the behavior of Drupal core.

File

core/modules/views/views.api.php, line 720
Describes hooks and plugins provided by the Views module.

Code

function hook_views_pre_build(ViewExecutable $view) {
  // Because of some inexplicable business logic, we should remove all
  // attachments from all views on Mondays.
  // (This alter could be done later in the execution process as well.)
  if (date('D') == 'Mon') {
    unset($view->attachment_before);
    unset($view->attachment_after);
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!views!views.api.php/function/hook_views_pre_build/8.1.x