Remember when Drupal 8 came out and everything had to become a class, and we all said we'd get around to it? Hooks were the one thing that got to stay the same. That's ending. Hooks are classes now, the #[Hook] attribute is how you write them, and every .module file you've been maintaining for the last decade has probably started throwing deprecation warnings about it.
Good news, everybody! You don't have to convert everything at once, and you probably shouldn't. This talk walks through migrating a custom module one hook at a time. We'll start by reading the deprecation notices and sorting out which ones matter, then convert a few hooks by hand so you can see what the attribute does and how discovery changed. From there we'll cover keeping the module working on pre- and post-attribute versions during the transition, where hook ordering behaves differently and how to check it, and what to do with hooks that were doing three unrelated jobs and should have been split years ago, not that any of us have ever done that.
Learning objectives:
- Convert a procedural hook implementation to an attribute-based hook class and verify it fires correctly
- Keep a module working across Drupal 11 and 12 while converting it incrementally
- Identify which hooks in a legacy module should be converted, split, or removed