function hook_views_post_build

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

Act on the view immediately after the query is built.

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 function implements hook_views_post_build()

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_post_build in core/modules/views/tests/modules/views_test_data/views_test_data.views_execution.inc
Implements hook_views_post_build().
1 invocation of hook_views_post_build()
ViewExecutable::build in core/modules/views/src/ViewExecutable.php
Builds the query for the view.

File

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

Code

function hook_views_post_build(ViewExecutable $view) {
    // If the exposed field 'type' is set, hide the column containing the content
    // type. (Note that this is a solution for a particular view, and makes
    // assumptions about both exposed filter settings and the fields in the view.
    // Also note that this alter could be done at any point before the view being
    // rendered.)
    if ($view->id() == 'my_view' && isset($view->exposed_raw_input['type']) && $view->exposed_raw_input['type'] != 'All') {
        // 'Type' should be interpreted as content type.
        if (isset($view->field['type'])) {
            $view->field['type']->options['exclude'] = TRUE;
        }
    }
}

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