Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

views_hooks_extras

5 sites Security covered
View on drupal.org

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
2 months ago
Release cadence
Stability
100% stable

Releases

Version Type Release date
1.0.0 Stable Jan 26, 2026