

Talking Drupal #510 - Drupal Hooks: Drop 'em like they're hot
13 snips Jul 7, 2025
Károly Negyesi, known as Chx, is a veteran Drupal contributor with over 21 years of experience. In this discussion, Chx delves into the evolution of Drupal hooks, explaining their transition from procedural to object-oriented programming. He addresses the challenges developers face and shares insights on the Media Folders module, which enhances media organization using a hierarchical structure. The conversation emphasizes community collaboration and the ongoing efforts to document changes, balancing innovation with backward compatibility in the Drupal ecosystem.
AI Snips
Chapters
Transcript
Episode notes
What Drupal Hooks Actually Are
- Hooks are a simple Drupal mechanism where modules implement named functions to alter core behavior.
- They act like events: Drupal asks "I'm about to do X, do you want to change it?" and runs matching functions.
Why Convert Hooks To OOP
- Moving hooks to object-oriented code was driven mainly by dependency injection and easier replacement of behavior.
- OOP isn't intrinsically superior, but PHP's tooling for classes enabled practical improvements.
Autowiring Was The Enabler
- Autowiring services in core (around 10.2) made object-oriented hooks feasible without heavy boilerplate.
- Autowiring lets services be dependency-injected automatically, keeping implementations slim.