This is the first in series of articles about the new hook system in Drupal. Let's start with a simple timeline of what each version provides!
11.1
Hooks can be defined in classes with the #[Hook] attribute.
Almost all hooks in .module files are supported!
Exceptions that must remain procedural
- hook_module_implements_alter
- hook_hook_info
- hook_preprocess
- hooks_preprocess_HOOK
- template_preprocess_HOOK
- hooks required to be in the .install file
- hooks required to be in the post_update files
- hooks in .theme files
11.2
- template_preprocess_HOOK can be defined as initital preprocess callbacks on hook_theme
- hook_preprocess and hook_preprocess_HOOK can be OOP (note this is only in modules)
- hook_requirements has been split into three new objects
- InstallRequirementsInterface (note this is no longer a hook)
- hook_update_requirements and alter
- hook_runtime_requirements and alter
- hook_hook_info has been made obsolete (IMPORTANT this is not your average deprecation, read carefully and don't be afraid to ask questions)
- hook_module_implements_alter hook ordering has been replaced with several ordering elements (BC is very complex don't be afraid to ask!)
Future