public function PathSubscriber::onKernelRequestPathResolve

Same name in this branch
  1. 9.x drupal/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php \Drupal\Core\EventSubscriber\PathSubscriber::onKernelRequestPathResolve()
  2. 9.x drupal/core/modules/system/tests/modules/url_alter_test/lib/Drupal/url_alter_test/PathSubscriber.php \Drupal\url_alter_test\PathSubscriber::onKernelRequestPathResolve()

Resolve the system path based on some arbitrary rules.

Parameters

Symfony\Component\HttpKernel\Event\GetResponseEvent $event: The Event to process.

File

drupal/core/modules/system/tests/modules/url_alter_test/lib/Drupal/url_alter_test/PathSubscriber.php, line 26
Contains Drupal\url_alter_test\PathSubscriber.

Class

PathSubscriber
Path subscriber for url_alter_test.

Namespace

Drupal\url_alter_test

Code

public function onKernelRequestPathResolve(GetResponseEvent $event) {
  $request = $event
    ->getRequest();
  $path = $this
    ->extractPath($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->uid . $matches[2];
    }
  }

  // Rewrite community/ to forum/.
  if ($path == 'community' || strpos($path, 'community/') === 0) {
    $path = 'forum' . substr($path, 9);
  }
  if ($path == 'url-alter-test/bar') {
    $path = 'url-alter-test/foo';
  }
  $this
    ->setPath($request, $path);
}