When Drupal receives an incoming request the HTTP Kernel identifies the appropriate route for the requested path. The routing system then matches this route with a controller that has been registered to handle responses for these types of requests. Sections of code responsible for generating the response to these requests are called Controllers.
- Write the code in a custom module that responds to particular incoming requests
- Understand how to identify the controllers responsible for responding to a given url, path and route.
Drupal's system of mapping request routes to controllers is quite well established. Since it's based on Symfony components it is unlikely to change dramatically in the foreseeable future.
This tutorial covers how controllers work in the Symfony framework. Because Drupal is built on top of Symfony components, controllers in Drupal are very similar.
Controllers and Form API
Adding a basic controller (Drupal.org)
- This tutorial covers creating a very basic controller.
Examples for Developers project's page_example module (git.drupalcode.org)
- The Examples project contains many sub-modules that demonstrate various Drupal sub-systems through well-documented code. To learn more about how routing and controllers work, take a look at the page_example module here.