function hook_views_pre_view

Same name in other branches
  1. 9 core/modules/views/views.api.php \hook_views_pre_view()
  2. 8.9.x core/modules/views/views.api.php \hook_views_pre_view()
  3. 11.x core/modules/views/views.api.php \hook_views_pre_view()

Alter a view at the very beginning of Views processing.

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.

string $display_id: The machine name of the active display.

array $args: An array of arguments passed into the view.

See also

\Drupal\views\ViewExecutable

Related topics

1 function implements hook_views_pre_view()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

views_test_data_views_pre_view in core/modules/views/tests/modules/views_test_data/views_test_data.views_execution.inc
Implements hook_views_pre_view().
1 invocation of hook_views_pre_view()
ViewExecutable::preExecute in core/modules/views/src/ViewExecutable.php
Runs attachments and lets the display do what it needs to before running.

File

core/modules/views/views.api.php, line 718

Code

function hook_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
    // Modify contextual filters for my_special_view if user has 'my special permission'.
    $account = \Drupal::currentUser();
    if ($view->id() == 'my_special_view' && $account->hasPermission('my special permission') && $display_id == 'public_display') {
        $args[0] = 'custom value';
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.