/** * Implements hook_views_pre_execute(). */ function {{ machine_name }}_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::messenger()->addWarning(t('The view %view may be heavy to execute.', ['%view' => $view->id()])); } }