Commit 2d9a2c8e authored by alexpott's avatar alexpott

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
......@@ -2,31 +2,23 @@
/**
* @file
* Contains Drupal\url_alter_test\PathSubscriber.
* Contains Drupal\url_alter_test\PathProcessor.
*/
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;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* 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.
*
* @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The Event to process.
* Implements Drupal\Core\PathProcessor\InboundPathProcessorInterface::processInbound().
*/
public function onKernelRequestPathResolve(GetResponseEvent $event) {
$request = $event->getRequest();
$path = $this->extractPath($request);
// Rewrite user/username to user/uid.
public function processInbound($path, Request $request) {
if (preg_match('!^user/([^/]+)(/.*)?!', $path, $matches)) {
if ($account = user_load_by_name($matches[1])) {
$matches += array(2 => '');
......@@ -42,18 +34,6 @@ public function onKernelRequestPathResolve(GetResponseEvent $event) {
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;
return $path;
}
}
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 }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment