You are here

public function PathProcessor::processInbound in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/url_alter_test/src/PathProcessor.php \Drupal\url_alter_test\PathProcessor::processInbound()

Processes the inbound path.

Implementations may make changes to the request object passed in but should avoid all other side effects. This method can be called to process requests other than the current request.

Parameters

string $path: The path to process, with a leading slash.

\Symfony\Component\HttpFoundation\Request $request: The HttpRequest object representing the request to process. Note, if this method is being called via the path_processor_manager service and is not part of routing, the current request object must be cloned before being passed in.

Return value

string The processed path.

Overrides InboundPathProcessorInterface::processInbound

File

core/modules/system/tests/modules/url_alter_test/src/PathProcessor.php, line 16

Class

PathProcessor
Path processor for url_alter_test.

Namespace

Drupal\url_alter_test

Code

public function processInbound($path, Request $request) {
  if (preg_match('!^/user/([^/]+)(/.*)?!', $path, $matches)) {
    if ($account = user_load_by_name($matches[1])) {
      $matches += [
        2 => '',
      ];
      $path = '/user/' . $account
        ->id() . $matches[2];
    }
  }

  // Rewrite community/ to forum/.
  $path = preg_replace('@^/community(.*)@', '/forum$1', $path);
  if ($path == '/url-alter-test/bar') {
    $path = '/url-alter-test/foo';
  }
  return $path;
}