Problem/Motivation
OOP hooks are coming.
Install hooks are particularly problematic.
Ghost of Drupal Past has a POC for adding the namespace.
https://www.drupal.org/project/drupal/issues/3442009#comment-15757035
Also see:
https://www.drupal.org/project/drupal/issues/3442009#comment-15754774
And:
https://www.drupal.org/project/drupal/issues/3442009#comment-15755910
Steps to reproduce
Proposed resolution
Determine if this should be split into multiple followups. The followups do not need to follow a particular order, but they were split up here for clarity.
Followup 1: Invoked in ModuleInstaller using ModuleHandler: All completed
Hooks that likely just need verification (convert an implementation and confirm it works)
These were excluded for scope on #3442009: OOP hooks using attributes and event dispatcher
#3486462: Support #Hook for several hooks called by ModuleInstaller
- hook_module_preinstall
- hook_module_preuninstall
- hook_modules_installed
- hook_modules_uninstalled
- hook_cache_flush
Followup 2: Theme Hooks in modules: All completed
Add new method on ModuleHandlerInterface to check for the existence of a hook
When the theme registry is built there is a hook check instead of function_exists.
The theme registry structure may need a change to store the module name so when ThemeManager fires them it can call them via ModuleHandler if it is a module implementing them similar to how the parent issue split hook_theme.
- template_preprocess #2340341: Move template_preprocess, _template_preprocess_default_variables into services
- template_preprocess_HOOK #3501136: Explicitly register template_preprocess callbacks in hook_theme()
- hook_preprocess #3495943: Handle module preprocess functions as OOP hooks
- hook_preprocess_HOOK #3495943: Handle module preprocess functions as OOP hooks
Followup 3 Hooks called by ModuleInstaller, Update system, and Drupal installer (except hook_requirements)
- hook_uninstall
- hook_post_update_NAME
- hook_install
- hook_install_tasks
- hook_install_tasks_alter
- hook_removed_post_updates
- hook_schema #3221051: [meta] Replace hook_schema() implementations with ::ensureTableExists() #2371709: Move the on-demand-table creation into the database API
- hook_update_dependencies
- hook_update_N #3167625: Deprecate/replace hook_update_N() in favor of an object-oriented approach similar to Laravel migrations
- hook_update_last_removed #3167625: Deprecate/replace hook_update_N() in favor of an object-oriented approach similar to Laravel migrations
Additional notes from Ghost:
We can add the module's namespace to the classloader then rebuild the container.
The issue is if during container rebuild anything fires a hook in the module to be installed (for example because entity definitions are requested, this is super common) that hook might not work because install did not run yet! Conclusion: install can't be an ordinary hook. The exact same reasoning applies converting install to any sort of service which is registered on the container. So if we can't inject services ... then what's the point of conversion? It could be moved into a magic named class like service provider but that's about it. I am guessing we could pass the container to this new thing so it can request services of already installed modules. (But then again, we could pass the container to hook_install just fine.
Followup 4: Metahooks: All completed
- hook_module_implements_alter #3485896: Hook ordering across OOP, procedural and with extra types i.e replace hook_module_implements_alter
- hook_hook_info #2233261: Deprecate hook_hook_info groups, mark hook_hook_info() for deletion
- Split hook_requirements into hook_install_requirements #3490843: Create class to replace hook_requirements('install')
hook_update_requirements and hook_runtime_requirements #3409372: [meta] Replace hook_requirements() with OOP classes
Followup 5: Themes and theme engines: All completed
- All hooks that can be implemented in themes #3544715: Add oop support to hooks currently supported by themes
- Alters that go through the theme alter process #3544715: Add oop support to hooks currently supported by themes
- hook_theme_registry_alter #3544715: Add oop support to hooks currently supported by themes
- hook_preprocess #3544715: Add oop support to hooks currently supported by themes
- hook_preprocess_HOOK #3544715: Add oop support to hooks currently supported by themes
- THEME_form_system_theme_settings_alter #3544715: Add oop support to hooks currently supported by themes
- THEME_views_pre_render #3544715: Add oop support to hooks currently supported by themes
- THEME_views_post_render #3544715: Add oop support to hooks currently supported by themes
- Maybe: THEMEPREFIX_engine_settings #1685492: Convert theme engines into services
Remaining tasks
Follow up 3
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
Comments
Comment #2
nicxvan commentedComment #3
nicxvan commentedComment #4
nicxvan commentedComment #5
nicxvan commentedComment #6
nicxvan commentedComment #7
nicxvan commentedComment #8
nicxvan commentedComment #9
nicxvan commentedComment #10
nicxvan commentedComment #11
nicxvan commentedComment #12
nicxvan commentedComment #13
nicxvan commentedComment #14
nicxvan commentedComment #15
nicxvan commentedComment #16
nicxvan commentedComment #17
nicxvan commentedComment #18
nicxvan commentedComment #19
nicxvan commentedComment #20
nicxvan commentedComment #21
nicxvan commentedComment #22
nicxvan commentedComment #23
nicxvan commentedComment #24
nicxvan commentedFollow up one hooks are all complete.
Comment #25
nicxvan commentedComment #26
nicxvan commentedComment #27
nicxvan commentedComment #28
nicxvan commentedComment #29
nicxvan commentedComment #30
nicxvan commentedComment #31
nicxvan commentedComment #32
nicxvan commentedComment #33
nicxvan commentedComment #34
nicxvan commentedComment #35
nicxvan commentedComment #36
nicxvan commentedComment #37
nicxvan commentedComment #38
nicxvan commentedComment #39
andypostComment #40
nicxvan commentedCan you help me understand how that is related?
Comment #41
nicxvan commentedComment #42
andypostThis is related cos planing transition to new hooks would be great to keep it in a mind
Comment #43
nicxvan commentedComment #44
nicxvan commentedFollow up 4 is done!
Comment #45
nicxvan commentedComment #46
nicxvan commentedComment #47
nicxvan commentedComment #48
nicxvan commentedComment #49
nicxvan commentedComment #50
nicxvan commentedComment #51
nicxvan commentedComment #52
nicxvan commentedComment #53
nicxvan commentedComment #54
nicxvan commentedComment #55
nicxvan commentedComment #57
nicxvan commented