class PathProcessorTest

Path processor for url_alter_test.

Hierarchy

Expanded class hierarchy of PathProcessorTest

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

File

drupal/core/modules/system/tests/modules/url_alter_test/lib/Drupal/url_alter_test/PathProcessorTest.php, line 17
Contains Drupal\url_alter_test\PathProcessorTest.

Namespace

Drupal\url_alter_test
View source
class PathProcessorTest implements InboundPathProcessorInterface, OutboundPathProcessorInterface {

  /**
   * Implements Drupal\Core\PathProcessor\InboundPathProcessorInterface::processInbound().
   */
  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->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';
    }
    return $path;
  }

  /**
   * Implements Drupal\Core\PathProcessor\OutboundPathProcessorInterface::processOutbound().
   */
  public function processOutbound($path, &$options = array(), Request $request = NULL) {

    // Rewrite user/uid to user/username.
    if (preg_match('!^user/([0-9]+)(/.*)?!', $path, $matches)) {
      if ($account = user_load($matches[1])) {
        $matches += array(
          2 => '',
        );
        $path = 'user/' . $account->name . $matches[2];
      }
    }

    // Rewrite forum/ to community/.
    if ($path == 'forum' || strpos($path, 'forum/') === 0) {
      $path = 'community' . substr($path, 5);
    }
    return $path;
  }

}

Members