Routes in Drupal can be altered as they are created, or even changed on the fly as the page request is being processed.
In addition to a routing system, Drupal has a path alias system where internal routes like “/node/123” can be given SEO friendly paths like “/about-us”. When the user visits the site at “/about-us” the path will be internally re-written to allow Drupal to serve the correct page. Modules like Pathauto will automatically generate the SEO friendly paths using information from the item of content; without the user having to remember to enter it themselves.
This mechanism is made possible thanks to an internal Drupal service called “path processing”. When Drupal receives a request it will pass the path through one or more path processors to allow them to change it to another path (which might be an internal route). The process is reversed when generating a link to the page, which allows the path processors to reverse the process.
It is possible to alter a route in Drupal using a route subscriber, but using path processors allows us to change or mask the route or path of a page in a Drupal site without actually changing the internal route itself.
In this article we will look what types path processors are available, how to create your own, what sort of uses they have in a Drupal site, and anything else you should look out for when creating path processors.
Types Of Path Processor
Path processors are managed by the Drupal class DrupalCorePathProcessorPathProcessorManager. When you add your a path processor to a site this is the class that manages the processor order and calling the processors.
There are two types of path processor available in Drupal: