mcpField
D
drupal-events

drupal-events

github.com/edutrul開発7349 回インストール21 週間前に更新
リポジトリ

drupal-events について

Drupal 開発者向けに、イベントサブスクライバーの定義と登録、代表的なカーネルイベントへの対応方法を示すスキルです。Drush による生成例も含みます。

主な機能

  1. 01イベントサブスクライバーの定義
  2. 02services.yml への登録
  3. 03代表的なカーネルイベントの確認
  4. 04Drush によるサブスクライバー生成

活用シーン

  1. 01リクエストやレスポンスイベントへの対応
  2. 02未処理例外の処理
  3. 03モジュール用サブスクライバーコードの生成

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/edutrul/drupal-ai --skill drupal-events

インストール後、Claude Code で/drupal-eventsを入力して読み込まれたか確認します。

同梱ファイルREADME.md

README(原文)English

プロジェクトの README より

この README の日本語訳はまだありません。以下は英語の原文です。日本語の紹介はページ上部をご覧ください。

Drupal Event Subscribers

Example (Best Practice)

// 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.
  }

}

Register in services.yml

services:
  my_module.my_event_subscriber:
    class: Drupal\my_module\EventSubscriber\MyEventSubscriber
    arguments: ['@current_user']
    tags:
      - { name: event_subscriber }

Common Events

EventConstantWhen
RequestKernelEvents::REQUESTEvery request
ResponseKernelEvents::RESPONSEBefore response sent
TerminateKernelEvents::TERMINATEAfter response sent
ExceptionKernelEvents::EXCEPTIONOn uncaught exception

Generate with Drush

drush generate event-subscriber --answers='{
  "module": "my_module",
  "class": "MyEventSubscriber",
  "event": "kernel.request"
}'

コメント