You are here

public function PathProcessorTest::processInbound in Zircon Profile 8

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

Processes the inbound path.

Parameters

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

\Symfony\Component\HttpFoundation\Request $request: The HttpRequest object representing the current request.

Return value

string The processed path.

Overrides InboundPathProcessorInterface::processInbound

File

core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php, line 24
Contains \Drupal\url_alter_test\PathProcessorTest.

Class

PathProcessorTest
Path processor for url_alter_test.

Namespace

Drupal\url_alter_test

Code

public function processInbound($path, Request $request) {

  // Rewrite user/username to user/uid.
  if (preg_match('!^/user/([^/]+)(/.*)?!', $path, $matches)) {
    if ($account = user_load_by_name($matches[1])) {
      $matches += array(
        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;
}