From 2d9a2c8ef98817534dbce1ace133fc14c4d362a3 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Wed, 24 Apr 2013 11:05:28 +0100 Subject: [PATCH] Issue #1976180 by katbailey: Fixed url_alter_test() module uses an event subscriber instead of a path processor. --- .../Drupal/url_alter_test/PathProcessor.php | 39 ++++++++++++ .../Drupal/url_alter_test/PathSubscriber.php | 59 ------------------- .../url_alter_test.services.yml | 4 +- 3 files changed, 41 insertions(+), 61 deletions(-) create mode 100644 core/modules/system/tests/modules/url_alter_test/lib/Drupal/url_alter_test/PathProcessor.php delete mode 100644 core/modules/system/tests/modules/url_alter_test/lib/Drupal/url_alter_test/PathSubscriber.php diff --git a/core/modules/system/tests/modules/url_alter_test/lib/Drupal/url_alter_test/PathProcessor.php b/core/modules/system/tests/modules/url_alter_test/lib/Drupal/url_alter_test/PathProcessor.php new file mode 100644 index 000000000000..b3611be40eb1 --- /dev/null +++ b/core/modules/system/tests/modules/url_alter_test/lib/Drupal/url_alter_test/PathProcessor.php @@ -0,0 +1,39 @@ +<?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; + } +} diff --git a/core/modules/system/tests/modules/url_alter_test/lib/Drupal/url_alter_test/PathSubscriber.php b/core/modules/system/tests/modules/url_alter_test/lib/Drupal/url_alter_test/PathSubscriber.php deleted file mode 100644 index 3f4f728a91ae..000000000000 --- a/core/modules/system/tests/modules/url_alter_test/lib/Drupal/url_alter_test/PathSubscriber.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php - -/** - * @file - * Contains Drupal\url_alter_test\PathSubscriber. - */ - -namespace Drupal\url_alter_test; - -use Drupal\Core\EventSubscriber\PathListenerBase; -use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; - -/** - * Path subscriber for url_alter_test. - */ -class PathSubscriber extends PathListenerBase implements EventSubscriberInterface { - - /** - * Resolve the system path based on some arbitrary rules. - * - * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event - * The Event to process. - */ - public function onKernelRequestPathResolve(GetResponseEvent $event) { - $request = $event->getRequest(); - $path = $this->extractPath($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'; - } - - $this->setPath($request, $path); - } - - /** - * Registers the methods in this class that should be listeners. - * - * @return array - * An array of event listener definitions. - */ - static function getSubscribedEvents() { - $events[KernelEvents::REQUEST][] = array('onKernelRequestPathResolve', 100); - return $events; - } -} diff --git a/core/modules/system/tests/modules/url_alter_test/url_alter_test.services.yml b/core/modules/system/tests/modules/url_alter_test/url_alter_test.services.yml index e65768238746..a05b3636c1fa 100644 --- a/core/modules/system/tests/modules/url_alter_test/url_alter_test.services.yml +++ b/core/modules/system/tests/modules/url_alter_test/url_alter_test.services.yml @@ -1,5 +1,5 @@ services: url_alter_test.path_subscriber: - class: Drupal\url_alter_test\PathSubscriber + class: Drupal\url_alter_test\PathProcessor tags: - - { name: event_subscriber } + - { name: path_processor_inbound, priority: 800 } -- GitLab