drupal-routing-controllers

Define Drupal routes and controllers mapping URLs to PHP code.

1|Updated Mar 11, 2026
One-click install
npx skills add https://github.com/proofoftom/drupal-skills --skill drupal-routing-controllers
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: drupal-routing-controllers
Source: https://github.com/proofoftom/drupal-skills/tree/main/skills/drupal-routing-controllers
Command: npx skills add https://github.com/proofoftom/drupal-skills --skill drupal-routing-controllers

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill helps developers define how users access content and functionality within a Drupal site by setting up URL routes and the PHP code (controllers) that handles requests.

Core Features & Use Cases

  • Route Definitions: Create .routing.yml files to map URLs to specific controller methods.
  • Controller Implementation: Write PHP classes to handle requests, return render arrays for pages, or JSON responses for APIs.
  • Dependency Injection: Properly inject services into controllers for cleaner, more maintainable code.
  • Use Case: When asked to create a new page at /my-module/items/{item_id} that displays item details and requires specific permissions, this Skill will generate the necessary .routing.yml entry and the corresponding controller class.

Quick Start

Use the drupal-routing-controllers skill to create a new page route for a custom content entity.

Frequently Asked Questions about drupal-routing-controllers

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

FAQPage Schema
How do I define Drupal routes and controllers for mapping URLs to PHP code?

To define Drupal routes and controllers, you create a `.routing.yml` file to map URLs to specific controller methods, then write PHP classes adhering to PSR-4 standards to handle requests and return render arrays or JSON responses.

How does dependency injection work in Drupal controllers?

Dependency injection in Drupal controllers involves properly passing required services into the controller class, which ensures cleaner, more maintainable code by decoupling the request handling logic from service implementation.

Can I create API endpoints returning JSON using Drupal routing?

Yes, you can create API endpoints returning JSON using Drupal routing by defining the URL path in your `.routing.yml` file and implementing the controller class to return JSON responses instead of render arrays.

What's the best way to add a custom page route with permissions in a Drupal module?

The best way to add a custom page route with permissions is to define the URL path and access requirements in a `.routing.yml` file, then implement the corresponding PHP controller method to generate the page content.

Do I need YAML to set up URL paths for custom Drupal modules?

Yes, you need YAML to set up URL paths for custom Drupal modules because the Drupal routing system requires a `.routing.yml` file to map URLs to executable PHP code within your module.

When should I use render arrays instead of direct HTML in Drupal controllers?

You should use render arrays instead of direct HTML in Drupal controllers when generating page content, as this adheres to Drupal's routing system standards and allows proper dependency injection and theme layer processing.