drupal-events

Implement Drupal 11 PSR-14 event subscribers with services.yml tags.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides guidance to implement and reason about Drupal's event-driven architecture using PSR-14 event subscribers, KernelEvents, and services.yml tags, helping teams decide between subscribers and hooks.

Core Features & Use Cases

  • Guidance on when to use event subscribers vs OOP hooks in Drupal 11
  • Examples of subscribing to KernelEvents and configuring subscribers via services.yml
  • Use cases across HTTP lifecycle, routing, and custom event handling

Quick Start

Create a minimal module and implement a KernelEvents::REQUEST subscriber that logs each request.

Frequently Asked Questions about drupal-events

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

FAQPage Schema
How do I implement event subscribers in Drupal 11?

To subscribe to KernelEvents in Drupal, create a class implementing EventSubscriberInterface, define getSubscribedEvents to map event constants to methods, and register it in services.yml using the event_subscriber tag.

When should I use event subscribers vs hooks in Drupal?

Use event subscribers instead of hooks when building responsive module logic across the HTTP lifecycle, as PSR-14 subscribers offer object-oriented event handling that integrates cleanly with Symfony events in Drupal 11.

How do I enforce execution order for multiple event subscribers?

Enforce execution order for event subscribers by configuring priority values within getSubscribedEvents, ensuring correct sequencing when multiple subscribers listen to the same KernelEvents in Drupal.

Can I handle custom events using PSR-14 in Drupal 11?

Yes, you can handle custom events using PSR-14 in Drupal 11 by defining the event object, dispatching it through the event dispatcher, and creating a subscriber class tagged in services.yml to respond to it.

What is the minimal setup to log a request using KernelEvents in Drupal?

The minimal setup to log a request using KernelEvents involves creating a basic module with a subscriber class listening to KernelEvents::REQUEST, then registering the service in services.yml to execute your logging logic.

Do I need services.yml to register a Drupal event subscriber?

Yes, you need services.yml to register a Drupal event subscriber because the file applies the required event_subscriber tag that allows the service container to recognize and activate your PSR-14 listener.