function PathProcessorTest::processOutbound

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

Overrides OutboundPathProcessorInterface::processOutbound

File

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

Class

PathProcessorTest
Path processor for url_alter_test.

Namespace

Drupal\url_alter_test

Code

public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
    // Rewrite user/uid to user/username.
    if (preg_match('!^/user/([0-9]+)(/.*)?!', $path, $matches)) {
        if ($account = User::load($matches[1])) {
            $matches += [
                2 => '',
            ];
            $path = '/user/' . $account->getAccountName() . $matches[2];
            if ($bubbleable_metadata) {
                $bubbleable_metadata->addCacheTags($account->getCacheTags());
            }
        }
    }
    // Verify that $options are alterable.
    if ($path == '/user/login') {
        $options['query']['foo'] = 'bar';
    }
    // Rewrite forum/ to community/.
    return preg_replace('@^/forum(.*)@', '/community$1', $path);
}

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