Add Support for OOP hooks

Created on 12 August 2025, 4 days ago

Problem/Motivation

In a D11 site here hooks have been converted to OOP implementation, we are getting the following error:

Call to undefined function indiecommerce_blog_scheduler_node_publish_process()

The error is legit, because the function does not exist. However, we have the following code in our Hooks class:

  /**
   * Implements hook_scheduler_ENTITY_TYPE_publish_process() for node.
   */
  #[Hook('scheduler_node_publish_process')]
  public function nodePublishProcess(NodeInterface $node): int {
    [..]
  }

Schedule module is capable to discover the hook implementation, however, it tries to execute the procedural hook instead of the implemented OOP version.

Steps to reproduce

Install a D11 site with Scheduler
Implemnt Scheduler hooks in OOP
Confirm that unexpected missing function errors are thrown

Proposed resolution

Fix it!

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.2

Component

Code

Created by

🇪🇸Spain plopesc Valladolid

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @plopesc
  • Merge request !250Issue #3540892: Add Support for OOP hooks → (Open) created by plopesc
  • 🇪🇸Spain plopesc Valladolid

    Created MR that allows to execute both OOP and traditional procedural hooks.

  • Pipeline finished with Success
    4 days ago
    #570815
  • 🇬🇧United Kingdom jonathan1055

    Hi plopesc,
    Thanks for raising this issue and for creating the MR. Yes this looks a good thing to do. Can you give a link to the documentation/explanation of how the OOP hooks work in Drupal, and in particular, why the line you changed

    $all_hook_implementations[] = $module . "_" . $hookName; 
    

    no longer needs the $module name?

    We also would need test coverage for this new feature, but I can look at that if you like.

Production build 0.71.5 2024