PathProcessor.php

Contains Drupal\url_alter_test\PathProcessor.

Namespace

Drupal\url_alter_test

File

drupal/core/modules/system/tests/modules/url_alter_test/lib/Drupal/url_alter_test/PathProcessor.php
View source
<?php

/**
 * @file
 * Contains Drupal\url_alter_test\PathProcessor.
 */
namespace Drupal\url_alter_test;

use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Symfony\Component\HttpFoundation\Request;

/**
 * Path processor for url_alter_test.
 */
class PathProcessor implements InboundPathProcessorInterface {

  /**
   * Implements Drupal\Core\PathProcessor\InboundPathProcessorInterface::processInbound().
   */
  public function processInbound($path, Request $request) {
    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;
  }

}

Classes

Namesort descending Description
PathProcessor Path processor for url_alter_test.