PathSubscriber.php in Drupal 8
File
core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php
View source
<?php
namespace Drupal\Core\EventSubscriber;
use Drupal\Core\Path\AliasManagerInterface;
use Drupal\Core\Path\CurrentPathStack;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PathSubscriber implements EventSubscriberInterface {
protected $aliasManager;
protected $currentPath;
public function __construct(AliasManagerInterface $alias_manager, CurrentPathStack $current_path) {
$this->aliasManager = $alias_manager;
$this->currentPath = $current_path;
$new_class = 'Drupal\\path_alias\\EventSubscriber\\PathAliasSubscriber';
if (!is_a($this, $new_class) && class_exists($new_class)) {
@trigger_error('The \\' . __CLASS__ . ' class is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Instead, use \\' . $new_class . '. See https://drupal.org/node/3092086', E_USER_DEPRECATED);
}
}
public function onKernelController(FilterControllerEvent $event) {
if ($event
->isMasterRequest()) {
$this->aliasManager
->setCacheKey(rtrim($this->currentPath
->getPath($event
->getRequest()), '/'));
}
}
public function onKernelTerminate(PostResponseEvent $event) {
$this->aliasManager
->writeCache();
}
public static function getSubscribedEvents() {
$events[KernelEvents::CONTROLLER][] = [
'onKernelController',
200,
];
$events[KernelEvents::TERMINATE][] = [
'onKernelTerminate',
200,
];
return $events;
}
}
Classes
Name |
Description |
PathSubscriber Deprecated |
Provides a path subscriber that converts path aliases. |