Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

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.

Activity

Total releases
1
First release
Jan 2026
Latest release
5 months ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Active

Releases

Version Type Release date
1.0.0 Stable Jan 26, 2026