Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Status
titleReviewed 230525

...

The following StackExchange explains how to achieve this if you would like to catch all parameters that fall below a particular path using the InboundPathProcessorInterface

http://drupal.stackexchange.com/questions/175758/slashes-in-single-route-parameter-or-other-ways-to-handle-a-menu-tail-with-dynam

...

  1. Add a file at mymodule/src/PathProcessor with the following code: 

    Code Block
    languagephp
    namespace Drupal\mymodule\PathProcessor;
    use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
    use Symfony\Component\HttpFoundation\Request;
    
    class HelloPathProcessor implements InboundPathProcessorInterface {
    
      public function processInbound($path, Request $request) {
        if (strpos($path, '/hello/') === 0) {
          $names = preg_replace('|^\/hello\/|', '', $path);
          $names = str_replace('/',':', $names);
          return "/hello/$names";
        }
        return $path;
      }
    
    }


  2. Register the class as a service in mymodule.services.yml



This turns everything after '/hello/' in the URL into a colon-separated string so that the dynamic route we registered at '/hello/{names}' gets fired. From there we can split the additional parameters, and use them as needed. This seems like a bit of a kludge but it's handy functionality sometimes and it's been a 'Drupalism' for some time now.

...