The Great Hook Migration: Getting Down with OOP

Session Category Development & Performance Audience Intermediate

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, 12, and 13 while converting it incrementally
  • Identify which hooks in a legacy module should be converted, split, or removed

About the Speaker

JD Flynn

Senior Software Engineer at HeroDevs

LaPorte, IN

JD Flynn has had mental illness most of his life, but didn't admit it until his early 30s when he decided it was time to do something about it. After a decade-long career in emergency services as a paramedic, JD made the jump from the ambulance to the text editor. Since then, JD has climbed to Principal Drupal Software Engineer in his current position.

His life was changed by OSMH (Open Sourcing Mental Health), a 501(c)(3) non-profit focused on opening the conversation on mental illness, which led him to telling his own story to as many people who would listen. As someone with mental illness who is not afraid to talk about it, JD has presented on the topic of Mental Illness in the Tech Community to local user groups, regional conferences, and national level events at locations such as MIT, UC Berkeley, Washington State Convention Center, Guaranteed Rate Field, and DePaul University.

More recently, JD has started streaming development on Twitch and has been learning new tools and languages on stream.  He streams under the name JDDoesDev and is desperate for your approval and attention.

When not speaking or coding, JD plays baritone saxophone in Windiana, a professional level wind ensemble out of Valparaiso, IN, and Michigan City Municipal Band, the oldest municipal band in Indiana.