function PathProcessorTest::processInbound

Same name in other branches
  1. 8.9.x core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php \Drupal\url_alter_test\PathProcessorTest::processInbound()
  2. 10 core/modules/forum/tests/modules/forum_url_alter_test/src/PathProcessorTest.php \Drupal\forum_url_alter_test\PathProcessorTest::processInbound()
  3. 10 core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php \Drupal\url_alter_test\PathProcessorTest::processInbound()
  4. 11.x core/modules/forum/tests/modules/forum_url_alter_test/src/PathProcessorTest.php \Drupal\forum_url_alter_test\PathProcessorTest::processInbound()
  5. 11.x core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php \Drupal\url_alter_test\PathProcessorTest::processInbound()

Overrides InboundPathProcessorInterface::processInbound

File

core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php, line 19

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 += [
                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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.