Skip to main content
replaced the link to the Git repository (which was anymore valid) with a class documentation link
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

In the routing system you can't do this. What you can do is path aliasing.

Inbound: /{bar}/foo/{baz} -> /foo/{bar}/{baz}

Outbound: /foo/{bar}/{baz} -> /{bar}/foo/{baz}

You need a pattern to apply a regular expression on the path inbound, so /{bar}/{baz} is only possible if the parameters themselves have a distinctive pattern.

I didn't find a tutorial how to build a pathprocessorpath processor, but you can use this example from core for the scaffolding: http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.phpPathProcessorFront class as example.

and registerRegister both as tagged service in *the .services.yml file for the module.

services:
  path_processor_front:
    class: Drupal\Core\PathProcessor\PathProcessorFront
    tags:
      - { name: path_processor_inbound, priority: 200 }
      - { name: path_processor_outbound, priority: 200 }
    arguments: ['@config.factory']

In the routing system you can't do this. What you can do is path aliasing.

Inbound: /{bar}/foo/{baz} -> /foo/{bar}/{baz}

Outbound: /foo/{bar}/{baz} -> /{bar}/foo/{baz}

You need a pattern to apply a regular expression on the path inbound, so /{bar}/{baz} is only possible if the parameters themselves have a distinctive pattern.

I didn't find a tutorial how to build a pathprocessor, but you can use this example from core for the scaffolding: http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php

and register both as tagged service in *.services.yml

services:
  path_processor_front:
    class: Drupal\Core\PathProcessor\PathProcessorFront
    tags:
      - { name: path_processor_inbound, priority: 200 }
      - { name: path_processor_outbound, priority: 200 }
    arguments: ['@config.factory']

In the routing system you can't do this. What you can do is path aliasing.

Inbound: /{bar}/foo/{baz} -> /foo/{bar}/{baz}

Outbound: /foo/{bar}/{baz} -> /{bar}/foo/{baz}

You need a pattern to apply a regular expression on the path inbound, so /{bar}/{baz} is only possible if the parameters themselves have a distinctive pattern.

I didn't find a tutorial how to build a path processor, but you can use the PathProcessorFront class as example.

Register both as tagged service in the .services.yml file for the module.

services:
  path_processor_front:
    class: Drupal\Core\PathProcessor\PathProcessorFront
    tags:
      - { name: path_processor_inbound, priority: 200 }
      - { name: path_processor_outbound, priority: 200 }
    arguments: ['@config.factory']
added 17 characters in body
Source Link
Darvanen
  • 4.1k
  • 17
  • 41

In the routing system you can't do this. What you can do is path aliasing.

Inbound: /{bar}/foo/{baz} -> /foo/{bar}/{baz}

Outbound: /foo/{bar}/{baz} -> /{bar}/foo/{baz}

You need a pattern to apply a regular expression on the path inbound, so /{bar}/{baz} is only possible if the parameters themselves have a distinctive pattern.

I didn't find a tutorial how to build a pathprocessor, but you can use this example from core for the scaffolding: http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php

and register both as tagged service in *.services.yml

services:
  path_processor_front:
    class: Drupal\Core\PathProcessor\PathProcessorFront
    tags:
      - { name: path_processor_inbound, priority: 200 }
      - { name: path_processor_outbound, priority: 200 }
    arguments: ['@config.factory']

In the routing system you can't do this. What you can do is path aliasing.

Inbound: /{bar}/foo/{baz} -> /foo/{bar}/{baz}

Outbound: /foo/{bar}/{baz} -> /{bar}/foo/{baz}

You need a pattern to apply a regular expression on the path inbound, so /{bar}/{baz} is only possible if the parameters themselves have a distinctive pattern.

I didn't find a tutorial how to build a pathprocessor, but you can use this example from core for the scaffolding: http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php

and register both as tagged service in *.services.yml

path_processor_front:
    class: Drupal\Core\PathProcessor\PathProcessorFront
    tags:
      - { name: path_processor_inbound, priority: 200 }
      - { name: path_processor_outbound, priority: 200 }
    arguments: ['@config.factory']

In the routing system you can't do this. What you can do is path aliasing.

Inbound: /{bar}/foo/{baz} -> /foo/{bar}/{baz}

Outbound: /foo/{bar}/{baz} -> /{bar}/foo/{baz}

You need a pattern to apply a regular expression on the path inbound, so /{bar}/{baz} is only possible if the parameters themselves have a distinctive pattern.

I didn't find a tutorial how to build a pathprocessor, but you can use this example from core for the scaffolding: http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php

and register both as tagged service in *.services.yml

services:
  path_processor_front:
    class: Drupal\Core\PathProcessor\PathProcessorFront
    tags:
      - { name: path_processor_inbound, priority: 200 }
      - { name: path_processor_outbound, priority: 200 }
    arguments: ['@config.factory']
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

In the routing system you can't do this. What you can do is path aliasing.

Inbound: /{bar}/foo/{baz} -> /foo/{bar}/{baz}

Outbound: /foo/{bar}/{baz} -> /{bar}/foo/{baz}

You need a pattern to apply a regular expression on the path inbound, so /{bar}/{baz} is only possible if the parameters themselves have a distinctive pattern.

I didn't find a tutorial how to build a pathprocessor, but you can use this example from core for the scaffolding: http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php

and register both as tagged service in *.services.yml

path_processor_front:
    class: Drupal\Core\PathProcessor\PathProcessorFront
    tags:
      - { name: path_processor_inbound, priority: 200 }
      - { name: path_processor_outbound, priority: 200 }
    arguments: ['@config.factory']