Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Usage Milestone: Time Field for Drupal 8+ Module time_field crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Views Hooks Extras

6 sites Security covered Drupal 8–11 Views ecosystem
View on drupal.org

This module provides more specific ways to hook into Views functionality, allowing developers to easily target individual views and their displays. This helps to reduce the need for lengthy conditional logic within existing hooks.

This module extends Views' native hooks to more specifically target particular views and their displays -- basically hook_form_FORM_ID_alter() for views hooks. This can help to avoid function calls with tons of conditional logic just to delineate which views are being targeted.

TL;DR:

Before: (╯°□°)╯︵ ┻━┻

function mymodule_views_pre_render(ViewExecutable $view) {
  switch ($view->id()) {
    case 'product_index':
      do_thing_1();
      if ($view->current_display === 'page_1') {
        do_thing_2();    
      }
       break;
    case 'users_list':
      do_thing_3();
      break;
  }
}

After: ┬─┬ノ( º _ ºノ)

function mymodule_extra_views_product_index_pre_render(ViewExecutable $view) {
  do_thing_1();
}

function mymodule_extra_views_product_index__page_1_pre_render(ViewExecutable $view) {
  do_thing_2();
}

function mymodule_extra_views_users_list_pre_render(ViewExecutable $view) {
  do_thing_3();
}

=======

Hooks take the format of:

  • hook_extra_viewsPrefix_VIEW_ID_viewsSuffix
  • hook_extra_viewsPrefix_VIEW_ID__DISPLAY_ID_viewsSuffix

Note that the DISPLAY_ID portion takes on the snake case version of the actual display ID. That is to say, if you happened to name your view display to be page-1, the hook would need to use page_1.

At time of writing, the following views hooks are currently supported:

  • hook_views_query_substitutions
  • hook_views_pre_view
  • hook_views_pre_build
  • hook_views_post_build
  • hook_views_pre_execute
  • hook_views_pre_render
  • hook_views_post_render
  • hook_views_query_alter
  • hook_views_preview_info_alter

Logic already exists to support the field_views and plugin hooks, but we aren't sure whether there's a way to parse a particular view or display ID from the available parameters. Feel free to open an issue if you have a solution for any of these hooks.

Shameless Self Promotion

A list of modules that I maintain:

  • Cache Register: A module aimed at improving developer quality of life surrounding caching.
  • Enum Generator: A developer utility that generates enums and class constants from a site's entities.
  • Views Hooks Extras: Extends Views' native hooks to more specifically target particular views and their displays

Image Credit

Cute fishing lure photo by Karolina Grabowska from Pexels.

Depends on

Dependencies of the latest stable release

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Jan 2026
Latest release
7 months ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Slowing

Releases

Version Type Core Release date
1.0.0 Stable 8–11 Jan 26, 2026