How do I implement the equivalent of hook_url_inbound_alter()? I'm working on a module which will resolve URLs to entities by altering inbound URLs so that if they contain an entity ID with following pattern "-{entity_id}" user will be redirected to correct URL.

A working example of the above:

Final URL:


http://romajazz.it/concerti/pozzovio-de-angelis-4902
Using the aliases:
http://romajazz.it/concerti/-4902
http://romajazz.it/concerti/i-can-type-anything-here-4902


I researched for a while; I found out there was hook_url_inbound_alter() in Drupal 7 which could solve this problem.

I also found that there is InboundPathProcessorInterface in Drupal 8.

I thought about implementing InboundPathProcessorInterface and use it in EventSubscriberInterface implementation which will subscribe on KernelEvents::REQUEST.

I wonder if this approach is correct. Are there any other ways of doing this in Drupal 8?
The PathProcessorAlias() class is probably your best example.


Create a module with a class the implements InboundPathProcessorInterface.
Create the service definition in your module.
Make sure your service has the path_processor_inbound service tag.  This will mark it for collection and tie it to the path processor.  You may need to play with the priority to change where it runs.


Your class will need to have some injected dependencies for looking up the entity.  EntityManager() got broken up recently, and I forget which ones you will really need.  You may also need/want the PathValidator() service.