drupal-services

Automate Drupal service dependency injection into controllers, forms, and plugins.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Dependency injection for Drupal controllers, forms, and plugins eliminates hard-coded service lookups, improving testability and maintainability.

Core Features & Use Cases

  • Provides DI patterns for Controllers, Forms, and Plugins using Drupal's container.
  • Encourages use of ContainerInjectionInterface and ContainerFactoryPluginInterface for clean wiring.
  • Recommends autowiring and standard service IDs via services.yml for decoupled, testable code.

Quick Start

Create a custom service in your module and inject it into a controller using ContainerInjectionInterface and services.yml.

Frequently Asked Questions about drupal-services

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

FAQPage Schema
How do I inject Drupal services into a controller?

You can inject Drupal services into a controller by implementing ContainerInjectionInterface and loading services from the container within the create() method for clean dependency injection.

What is the best way to use dependency injection in Drupal plugins?

The best way to use dependency injection in Drupal plugins is implementing ContainerFactoryPluginInterface, which allows standard service IDs to be passed cleanly through the container to the plugin constructor.

Does Drupal 10.3 support autowiring for services?

Yes, Drupal 10.3 supports autowiring for dependency injection. Define your services and standard service IDs in services.yml to enable autowiring for decoupled, testable code.

Why use dependency injection instead of Drupal::service?

Dependency injection replaces Drupal::service to eliminate hard-coded service lookups, making controllers, forms, and plugins significantly more testable and maintainable through decoupled code.

How do I define a custom service in services.yml for dependency injection?

Define a custom service in services.yml by specifying the class path and arguments, enabling autowiring to resolve dependencies automatically for clean integration into your Drupal forms and controllers.

Can I use ContainerInjectionInterface with Drupal forms?

Yes, you can use ContainerInjectionInterface with Drupal forms to cleanly wire services like entity_type.manager and current_user, replacing hard-coded lookups and ensuring proper testability.