drupal-hooks

Implement Drupal 11 hooks in procedural and OOP styles with DI.

67|13|Updated Apr 15, 2026
One-click install
npx skills add https://github.com/edutrul/drupal-ai --skill drupal-hooks
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: drupal-hooks
Source: https://github.com/edutrul/drupal-ai/tree/main/.claude/skills/drupal-hooks
Command: npx skills add https://github.com/edutrul/drupal-ai --skill drupal-hooks

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps Drupal developers understand and implement hooks across procedural and object-oriented styles, clarifying when to use hooks versus events and how to structure modules for Drupal 11.

Core Features & Use Cases

  • OOP Hooks: Auto-registered hooks in src/Hook for Drupal 11.
  • Procedural Hooks: Classic hook_form_alter and other procedural hooks in .module files.
  • Decision Guidance: Clear criteria on when to use hook_form_alter vs event subscribers.

Quick Start

Create an OOP hook in your Drupal 11 module using #[Hook] to handle a specific form alteration.

Frequently Asked Questions about drupal-hooks

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a Drupal 11 hook_form_alter using OOP instead of procedural code?

Drupal 11 OOP hooks use the #[Hook] attribute and are auto-registered in the src/Hook directory. This modern pattern replaces procedural hook_form_alter implementations while maintaining the same alteration capabilities for your module development.

When should I use Drupal hooks versus event subscribers in module development?

Drupal hooks are suitable for form alterations and node presave operations, while event subscribers are preferred for decoupled logic. This skill provides decision guidance to choose between procedural hooks and OOP events based on your specific use case.

Does Drupal 11 still support procedural hooks in .module files?

Yes, Drupal 11 continues to support classic procedural hooks like hook_form_alter in .module files. You can use procedural implementations alongside modern OOP hooks depending on your module's architectural needs.

What is the correct namespace placement for OOP hooks in Drupal 11?

OOP hooks in Drupal 11 must be placed in the src/Hook directory with proper namespace structure. This ensures auto-registration works correctly with the #[Hook] attribute and dependency injection patterns.

Can I use dependency injection with Drupal 11 hooks?

Yes, Drupal 11 OOP hooks support dependency injection through the modern auto-registration system. This allows you to inject services directly into your hook classes rather than using procedural service calls.

Why use OOP hooks over procedural hooks in Drupal 11?

OOP hooks offer better testability, dependency injection support, and cleaner code organization through auto-registration. Procedural hooks remain viable for simple alterations, but OOP provides modern patterns for complex module development.