class PathProcessorTest

Same name in this branch
  1. 10 core/modules/forum/tests/modules/forum_url_alter_test/src/PathProcessorTest.php \Drupal\forum_url_alter_test\PathProcessorTest
  2. 10 core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php \Drupal\Tests\Core\PathProcessor\PathProcessorTest
Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php \Drupal\url_alter_test\PathProcessorTest
  2. 9 core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php \Drupal\Tests\Core\PathProcessor\PathProcessorTest
  3. 8.9.x core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php \Drupal\url_alter_test\PathProcessorTest
  4. 8.9.x core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php \Drupal\Tests\Core\PathProcessor\PathProcessorTest
  5. 11.x core/modules/forum/tests/modules/forum_url_alter_test/src/PathProcessorTest.php \Drupal\forum_url_alter_test\PathProcessorTest
  6. 11.x core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php \Drupal\url_alter_test\PathProcessorTest
  7. 11.x core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php \Drupal\Tests\Core\PathProcessor\PathProcessorTest

Path processor for url_alter_test.

Hierarchy

  • class \Drupal\url_alter_test\PathProcessorTest implements \Drupal\Core\PathProcessor\InboundPathProcessorInterface, \Drupal\Core\PathProcessor\OutboundPathProcessorInterface

Expanded class hierarchy of PathProcessorTest

1 string reference to 'PathProcessorTest'
url_alter_test.services.yml in core/modules/system/tests/modules/url_alter_test/url_alter_test.services.yml
core/modules/system/tests/modules/url_alter_test/url_alter_test.services.yml
1 service uses PathProcessorTest
url_alter_test.path_processor in core/modules/system/tests/modules/url_alter_test/url_alter_test.services.yml
Drupal\url_alter_test\PathProcessorTest

File

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

Namespace

Drupal\url_alter_test
View source
class PathProcessorTest implements InboundPathProcessorInterface, OutboundPathProcessorInterface {
    
    /**
     * {@inheritdoc}
     */
    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];
            }
        }
        if ($path == '/url-alter-test/bar') {
            $path = '/url-alter-test/foo';
        }
        return $path;
    }
    
    /**
     * {@inheritdoc}
     */
    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';
        }
        return $path;
    }

}

Members

Title Sort descending Modifiers Object type Summary
PathProcessorTest::processInbound public function
PathProcessorTest::processOutbound public function

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