一键导入
drupal-events
Drupal event subscribers — Symfony events (PSR-14), KernelEvents, services.yml tags, and hooks vs events decision guide.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Drupal event subscribers — Symfony events (PSR-14), KernelEvents, services.yml tags, and hooks vs events decision guide.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
HTMX in Drupal 11.3+ core — the Htmx PHP fluent builder, dynamic forms with swapOob, partial routes with _htmx_route, response headers, and Drupal.behaviors integration. Use when building interactive UI without full-page reloads using Drupal's native HTMX support.
DDEV local development expertise. Use when working with DDEV projects, containers, configuration, or troubleshooting DDEV environments.
Custom Docker Compose local development patterns. Use when working with Docker-based local environments, container configuration, or troubleshooting Docker setups.
Drupal access control — permissions.yml, access callbacks, AccessResult, custom access checkers, and entity access.
Drupal Cache API — cache tags, contexts, max-age, cache bins, invalidation, and adding cache metadata to render arrays.
Drupal Composer management — requiring modules, updates, patches via composer-patches, and version constraints.
| name | drupal-events |
| description | Drupal event subscribers — Symfony events (PSR-14), KernelEvents, services.yml tags, and hooks vs events decision guide. |
// src/EventSubscriber/MyEventSubscriber.php
namespace Drupal\my_module\EventSubscriber;
use Drupal\Core\Session\AccountProxyInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
final class MyEventSubscriber implements EventSubscriberInterface {
public function __construct(
private readonly AccountProxyInterface $currentUser,
) {}
public static function getSubscribedEvents(): array {
return [
// Note: Higher priority runs earlier. Default is 0.
KernelEvents::REQUEST => ['onRequest', 100],
];
}
public function onRequest(RequestEvent $event): void {
if (!$event->isMainRequest()) {
return;
}
if (!$this->currentUser->isAuthenticated()) {
return;
}
// Example: log or modify behavior for authenticated users.
}
}
services:
my_module.my_event_subscriber:
class: Drupal\my_module\EventSubscriber\MyEventSubscriber
arguments: ['@current_user']
tags:
- { name: event_subscriber }
| Event | Constant | When |
|---|---|---|
| Request | KernelEvents::REQUEST | Every request |
| Response | KernelEvents::RESPONSE | Before response sent |
| Terminate | KernelEvents::TERMINATE | After response sent |
| Exception | KernelEvents::EXCEPTION | On uncaught exception |
drush generate event-subscriber --answers='{
"module": "my_module",
"class": "MyEventSubscriber",
"event": "kernel.request"
}'