- Issue created by @plopesc
- 🇪🇸Spain plopesc Valladolid
Created MR that allows to execute both OOP and traditional procedural hooks.
- 🇬🇧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.
- 🇪🇸Spain plopesc Valladolid
@jonathan1055 Thank you for taking a look into this.
It is not necessary to custom build the callable string concatenating the
$module
and the$hookName
variables when we already have the$hook
variable that does it for you.Example for procedural hooks:
- $module = 'my_module'
- $hookName = 'hook'
- $hook = '\my_module_hook'
- $module . "_" . $hookName = 'my_module_hook'
There is no difference and hook is invoked because the custom variable represents the same function as $hook.
Example for OOP hooks:
- $module = 'my_module'
- $hookName = 'hook'
- $hook = [
'\Drupal\my_module\Hook\MyModuleHooks', - $module . "_" . $hookName = 'my_module_hook'
'hook',
]
The custom variable points to an undefined function instead of the actual method that implements the hook.
- 🇬🇧United Kingdom jonathan1055
Thanks. I have also added a link to the core change record.
I will add test coverage for this too, before merging.
Also in the long term, it might be good to look at convertiing Scheduler's own hook implementations into OOP hooks, but that's for later.