You are here

function hook_views_pre_build in Views (for Drupal 7) 8.3

Same name and namespace in other branches
  1. 6.3 docs/docs.php \hook_views_pre_build()
  2. 6.2 docs/docs.php \hook_views_pre_build()
  3. 7.3 views.api.php \hook_views_pre_build()

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

1 invocation of hook_views_pre_build()
ViewExecutable::build in lib/Drupal/views/ViewExecutable.php
Build the query for the view.

File

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

Code

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.)
  if (date('D') == 'Mon') {
    unset($view->attachment_before);
    unset($view->attachment_after);
  }
}