Commit 2ceb9c02 authored by Crell's avatar Crell
Browse files

Refactor path manipulation code to make it easier to extend.

parent a390ba77
<?php
namespace Drupal\Core\EventSubscriber;
use Symfony\Component\HttpFoundation\Request;
/**
* Description of PathListenerAbstract
*/
abstract class PathListenerAbstract {
public function extractPath(Request $request) {
return $request->attributes->get('system_path') ?: ltrim($request->getPathInfo(), '/');
}
public function setPath(Request $request, $path) {
$request->attributes->set('system_path', $path);
// @todo Remove this line once code has been refactored to use the request
// object directly.
_current_path($path);
}
}
......@@ -16,7 +16,7 @@
/**
* Access subscriber for controller requests.
*/
class PathSubscriber implements EventSubscriberInterface {
class PathSubscriber extends PathListenerAbstract implements EventSubscriberInterface {
/**
* Resolve the system path.
......@@ -31,7 +31,7 @@ public function onKernelRequestPathResolve(GetResponseEvent $event) {
$request = $event->getRequest();
$path = ltrim($request->getPathInfo(), '/');
$path = $this->extractPath($request);
if (empty($path)) {
// @todo Temporary hack. Fix when configuration is injectable.
......@@ -44,11 +44,28 @@ public function onKernelRequestPathResolve(GetResponseEvent $event) {
$system_path = variable_get('site_frontpage', 'user');
}
$request->attributes->set('system_path', $system_path);
$this->setPath($request, $system_path);
}
/**
* Resolve the front-page default path.
*
* @todo The path system should be objectified to remove the function calls
* in this method.
*
* @param GetResponseEvent $event
* The Event to process.
*/
public function onKernelRequestFrontPageResolve(GetResponseEvent $event) {
$request = $event->getRequest();
$path = $this->extractPath($request);
if (empty($path)) {
// @todo Temporary hack. Fix when configuration is injectable.
$path = variable_get('site_frontpage', 'user');
}
// @todo Remove this line once code has been refactored to use the request
// object directly.
_current_path($system_path);
$this->setPath($request, $path);
}
/**
......@@ -59,6 +76,7 @@ public function onKernelRequestPathResolve(GetResponseEvent $event) {
*/
static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = array('onKernelRequestPathResolve', 100);
$events[KernelEvents::REQUEST][] = array('onKernelRequestFrontPageResolve', 101);
return $events;
}
......
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