Views: Provide views / display specific hooks

Created on 31 October 2014, almost 11 years ago
Updated 16 April 2025, 4 months ago

Problem/Motivation

Currently views has some hooks that are very generic. Implementing those hooks for several views configurations leads to code that's hard to read.
An example (attention might be D7 specific) is hook_views_exposed_form_alter(). This is even a special case because it's basically an implementation of hook_form_FORM_ID_alter().
However, if you've to adjust multiple exposed forms from views you've to add quite some conditions in your implementation.

Proposed resolution

Trigger views name / display name specific views hooks.
A very ugly but trivial solution for a D7 hook_views_exposed_form_VIEWS_NAME_DISPLAY_NAME_alter() could look like:

/**
 * Form builder for the exposed widgets form.
 *
 * Be sure that $view and $display are references.
 */
function views_exposed_form($form, &$form_state) {
....
  // Save the form
  views_exposed_form_cache($view->name, $view->current_display, $form);

  // Invoke hook_views_exposed_form_VIEWS_NAME_DISPLAY_NAME_alter().
  drupal_alter('views_exposed_form_' . $view->name  . '_' . $view->current_display, $form, $form_state);

  return $form;
}

Remaining tasks

User interface changes

API changes

New hooks.

✨ Feature request
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

views.module

Created by

πŸ‡¨πŸ‡­Switzerland das-peter

Live updates comments and jobs are added and updated live.
  • VDC

    Related to the Views in Drupal Core initiative.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for sharing your idea for improving Drupal.

    We are working to decide if this proposal meets the Criteria for evaluating proposed changes. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or there is no community support. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

  • Status changed to Closed: outdated 7 days ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Since there's been no follow up on this feature request going to close this one out. If still desired please feel free to re-open.

Production build 0.71.5 2024