Drupaly Things - NCIOCPL/cgov-digital-platform GitHub Wiki
Things supporting the handling of a request
The exact order of things below is a little fuzzy, but this is in general what happens.
User Requests a URL
|
V
This manipulates the Requested URL into a URL that matches a Route. The main method is the processInbound that takes the requested path and request object, and returns the path that should be used. These classes are services and are identified as InboundPathProcessors by a path_processor_inbound
tag. The priority can be set allowing you to process a URL earlier in the process, or after something.
Examples of InboundPathProcessors are:
- Drupal\Core\PathProcessor\PathProcessorAlias - replaces an alias with its route, e.g. /foo/bar => /node/123
- Drupal\Core\PathProcessor\PathProcessorFront - handles requests for '/', rewriting to be the site settings' page.front value.
ASIDE: This interface has a close friend, OutboundPathProcessorInterface. OutboundPathProcessorInterface manipulates URLs when the URL Generator is used in methods like $entity->toUrl()
. If you look at the InboundPathProcessors listed above, you will see they also implement the OutboundPathProcessorInterface as well. This makes sense as the PathProcessorAlias has a job to ensure any request to generate a URL that has an alias should use the alias instead of the raw URL (e.g. /node/123).
|
V
A route primarily has 2 things:
- A pattern to match against a requested URL, e.g. /node/<NODE_ID_HERE> (or more correctly /node/{node})
- A controller (and its method) to handle the requested URL if the pattern matches.
Additionally it also defines things like what roles can access the route, what parameters are expected, etc.
Routes can be defined and manipulated by:
-
Creating a my_module.routing.yml file. (Definition only)
-
Implementing a RouteSubscriber (Definition & Alteration)
-
...others?
| V
(NOTE: I linked to ControllerBase, but you probably can find a better base.)
In a route definition, a controller class is defined with the method that will be used to handle the request. These methods usually return a render array that is passed to the drupal renderer to handle the rendering of the page and response. A Controller can also return a Symfony Response if your controller is going to handle a raw response.