Allow Implements hook_foo_BAR_ID_bar() for 'xyz_bar'.

Created on 1 December 2017, over 7 years ago
Updated 29 January 2025, 2 months ago

Problem/Motivation

When implementing a hook following the hook_foo_BAR_ID_bar() pattern, the following formats are allowed (at least for D7):

  • * Implements hook_foo_BAR_ID_bar() for xyz_bar().
  • * Implements hook_foo_BAR_ID_bar() for xyz-bar.html.twig.
  • * Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.

For some hooks I think this can look misleading as in the following examples:

  • /**
     * Implements hook_ENTITY_TYPE_load() for node().
     */
    
  • /**
     * Implements hook_feeds_PLUGIN_TYPE_config_defaults() for parser().
     */
    

The enforcement on ending the item reference with parentheses, implies that the referenced item is a function, which in the above two examples it is not.

Background

While working on improving the coding standards for the D7 version of Feeds, I got warned about a coding standards violation for the following piece of code:

/**
 * Implements hook_features_pipe_COMPONENT_alter() for 'feeds_importer'.
 *
 * Automatically adds dependencies when a Feed importer is selected in Features.
 */

See https://www.drupal.org/pift-ci-job/824119

Proposed resolution

I therefore propose to also allow this format:

* Implements hook_foo_BAR_ID_bar() for 'xyz_bar'.

Its use however MUST be limited to items that are not a function nor a template.

Existing issues

I've been looking for existing issues to find out if there maybe is a specific reason for why the proposed format would not be allowed, but I couldn't find one so far. What I did find:

Format is already used in D8 core

I saw that D8 core already uses this format and also similar formats.

  • From field.module, Drupal 8.4.2:
    /**
     * Implements hook_ENTITY_TYPE_update() for 'field_storage_config'.
     *
     * Reset the field handler settings, when the storage target_type is changed on
     * an entity reference field.
     */
  • From block.module, Drupal 8.4.2:
    /**
     * Implements hook_ENTITY_TYPE_delete() for 'configurable_language'.
     *
     * Delete the potential block visibility settings of the deleted language.
     */

Other formats used in core:

  • From block.module, Drupal 8.4.2:
    /**
     * Implements hook_ENTITY_TYPE_delete() for menu entities.
     */
  • From node.module, Drupal 8.4.2:
    /**
    * Implements hook_ENTITY_TYPE_predelete() for user entities.
    */
Feature request
Status

Postponed: needs info

Component

Coding Standards

Created by

🇳🇱Netherlands megachriz

Live updates comments and jobs are added and updated live.
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.

Production build 0.71.5 2024