Module Development

Concept: Controllers for Drupal 8, 9, 10, and 11

Controllers are where you place the custom logic to dynamically generate the content of a page that a visitor sees when they visit a URL. When Drupal receives an incoming request, the HttpKernel identifies the appropriate route for the requested path, and the routing system matches this route with a controller. Controllers generate responses to these requests.

In this tutorial, we'll:

  • Understand what a controller is in PHP and in the context of a Drupal module.
  • Learn how to identify and interpret the role of a controller class.

By the end of this tutorial, you should be able to identify a controller class in a Drupal module and understand its role in generating responses.

Drupal Module Developer Guide