Skip to content
Snippets Groups Projects
Commit 2d9a2c8e authored by Alex Pott's avatar Alex Pott
Browse files

Issue #1976180 by katbailey: Fixed url_alter_test() module uses an event...

Issue #1976180 by katbailey: Fixed url_alter_test() module uses an event subscriber instead of a path processor.
parent af11d7b2
No related branches found
No related tags found
No related merge requests found
...@@ -2,31 +2,23 @@ ...@@ -2,31 +2,23 @@
/** /**
* @file * @file
* Contains Drupal\url_alter_test\PathSubscriber. * Contains Drupal\url_alter_test\PathProcessor.
*/ */
namespace Drupal\url_alter_test; namespace Drupal\url_alter_test;
use Drupal\Core\EventSubscriber\PathListenerBase; use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/** /**
* Path subscriber for url_alter_test. * Path processor for url_alter_test.
*/ */
class PathSubscriber extends PathListenerBase implements EventSubscriberInterface { class PathProcessor implements InboundPathProcessorInterface {
/** /**
* Resolve the system path based on some arbitrary rules. * Implements Drupal\Core\PathProcessor\InboundPathProcessorInterface::processInbound().
*
* @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The Event to process.
*/ */
public function onKernelRequestPathResolve(GetResponseEvent $event) { public function processInbound($path, Request $request) {
$request = $event->getRequest();
$path = $this->extractPath($request);
// Rewrite user/username to user/uid.
if (preg_match('!^user/([^/]+)(/.*)?!', $path, $matches)) { if (preg_match('!^user/([^/]+)(/.*)?!', $path, $matches)) {
if ($account = user_load_by_name($matches[1])) { if ($account = user_load_by_name($matches[1])) {
$matches += array(2 => ''); $matches += array(2 => '');
...@@ -42,18 +34,6 @@ public function onKernelRequestPathResolve(GetResponseEvent $event) { ...@@ -42,18 +34,6 @@ public function onKernelRequestPathResolve(GetResponseEvent $event) {
if ($path == 'url-alter-test/bar') { if ($path == 'url-alter-test/bar') {
$path = 'url-alter-test/foo'; $path = 'url-alter-test/foo';
} }
return $path;
$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;
} }
} }
services: services:
url_alter_test.path_subscriber: url_alter_test.path_subscriber:
class: Drupal\url_alter_test\PathSubscriber class: Drupal\url_alter_test\PathProcessor
tags: tags:
- { name: event_subscriber } - { name: path_processor_inbound, priority: 800 }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment