W3cubDocs

/Drupal 8

function hook_views_pre_execute

hook_views_pre_execute(ViewExecutable $view)

Act on the view after the query is built and just before it is executed.

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 766
Describes hooks and plugins provided by the Views module.

Code

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
  // earlier.)
  $account = \Drupal::currentUser();

  if (count($view->query->tables) > 2 && $account->hasPermission('administer views')) {
    drupal_set_message(t('The view %view may be heavy to execute.', array('%view' => $view->name)), 'warning');
  }
}

© 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_execute/8.1.x