diff --git a/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php index 3d72b0d..c64f98c 100644 --- a/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php @@ -8,7 +8,7 @@ namespace Drupal\Core\EventSubscriber; use Drupal\Core\Path\AliasManagerInterface; -use Drupal\Core\Path\CurrentPath; +use Drupal\Core\Path\CurrentPathStack; use Drupal\Core\PathProcessor\InboundPathProcessorInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -38,7 +38,7 @@ class PathSubscriber implements EventSubscriberInterface { /** * The current path. * - * @var \Drupal\Core\Path\CurrentPath + * @var \Drupal\Core\Path\CurrentPathStack */ protected $currentPath; @@ -47,10 +47,10 @@ class PathSubscriber implements EventSubscriberInterface { * * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager * @param \Drupal\Core\PathProcessor\InboundPathProcessorInterface $path_processor - * @param \Drupal\Core\Path\CurrentPath $current_path + * @param \Drupal\Core\Path\CurrentPathStack $current_path * The current path. */ - public function __construct(AliasManagerInterface $alias_manager, InboundPathProcessorInterface $path_processor, CurrentPath $current_path) { + public function __construct(AliasManagerInterface $alias_manager, InboundPathProcessorInterface $path_processor, CurrentPathStack $current_path) { $this->aliasManager = $alias_manager; $this->pathProcessor = $path_processor; $this->currentPath = $current_path; @@ -66,6 +66,7 @@ public function onKernelRequestConvertPath(GetResponseEvent $event) { $request = $event->getRequest(); $path = trim($request->getPathInfo(), '/'); $path = $this->pathProcessor->processInbound($path, $request); + $path = '/' . $path; $this->currentPath->setPath($path, $request); // Set the cache key on the alias manager cache decorator. diff --git a/core/lib/Drupal/Core/Path/CurrentPathStack.php b/core/lib/Drupal/Core/Path/CurrentPathStack.php index bd0d647..67bcf8c 100644 --- a/core/lib/Drupal/Core/Path/CurrentPathStack.php +++ b/core/lib/Drupal/Core/Path/CurrentPathStack.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\Path\CurrentPath. + * Contains \Drupal\Core\Path\CurrentPathStack. */ namespace Drupal\Core\Path; @@ -32,7 +32,7 @@ class CurrentPathStack { protected $requestStack; /** - * Constructs a new CurrentPath instance. + * Constructs a new CurrentPathStack instance. * * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * The request stack. diff --git a/core/lib/Drupal/Core/Routing/RouteProvider.php b/core/lib/Drupal/Core/Routing/RouteProvider.php index 81e26d7..eaec9fe 100644 --- a/core/lib/Drupal/Core/Routing/RouteProvider.php +++ b/core/lib/Drupal/Core/Routing/RouteProvider.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Routing; use Drupal\Component\Utility\String; -use Drupal\Core\Path\CurrentPath; +use Drupal\Core\Path\CurrentPathStack; use Drupal\Core\State\StateInterface; use Symfony\Cmf\Component\Routing\PagedRouteCollection; use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface; @@ -63,7 +63,7 @@ class RouteProvider implements RouteProviderInterface, PagedRouteProviderInterfa /** * The current path. * - * @var \Drupal\Core\Path\CurrentPath + * @var \Drupal\Core\Path\CurrentPathStack */ protected $currentPath; @@ -76,12 +76,12 @@ class RouteProvider implements RouteProviderInterface, PagedRouteProviderInterfa * The route builder. * @param \Drupal\Core\State\StateInterface $state * The state. - * @param \Drupal\Core\Path\CurrentPath $current_path + * @param \Drupal\Core\Path\CurrentPathStack $current_path * THe current path. * @param string $table * The table in the database to use for matching. */ - public function __construct(Connection $connection, RouteBuilderInterface $route_builder, StateInterface $state, CurrentPath $current_path, $table = 'router') { + public function __construct(Connection $connection, RouteBuilderInterface $route_builder, StateInterface $state, CurrentPathStack $current_path, $table = 'router') { $this->connection = $connection; $this->routeBuilder = $route_builder; $this->state = $state; @@ -115,7 +115,7 @@ public function __construct(Connection $connection, RouteBuilderInterface $route * @todo Should this method's found routes also be included in the cache? */ public function getRouteCollectionForRequest(Request $request) { - $path = '/' . $this->currentPath->getPath($request); + $path = $this->currentPath->getPath($request); $collection = $this->getRoutesByPath($path); diff --git a/core/lib/Drupal/Core/Routing/UrlMatcher.php b/core/lib/Drupal/Core/Routing/UrlMatcher.php index 088353c..dbd95d3 100644 --- a/core/lib/Drupal/Core/Routing/UrlMatcher.php +++ b/core/lib/Drupal/Core/Routing/UrlMatcher.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Routing; -use Drupal\Core\Path\CurrentPath; +use Drupal\Core\Path\CurrentPathStack; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\RouteCollection; use Symfony\Cmf\Component\Routing\NestedMatcher\UrlMatcher as BaseUrlMatcher; @@ -20,7 +20,7 @@ class UrlMatcher extends BaseUrlMatcher { /** * The current path. * - * @var \Drupal\Core\Path\CurrentPath + * @var \Drupal\Core\Path\CurrentPathStack */ protected $currentPath; @@ -30,10 +30,10 @@ class UrlMatcher extends BaseUrlMatcher { * The parent class has a constructor we need to skip, so just override it * with a no-op. * - * @param \Drupal\Core\Path\CurrentPath $current_path + * @param \Drupal\Core\Path\CurrentPathStack $current_path * The current path. */ - public function __construct(CurrentPath $current_path) { + public function __construct(CurrentPathStack $current_path) { $this->currentPath = $current_path; } @@ -42,9 +42,8 @@ public function finalMatch(RouteCollection $collection, Request $request) { $context = new RequestContext(); $context->fromRequest($request); $this->setContext($context); - $path = '/' . $this->currentPath->getPath($request); - return $this->match($path); + return $this->match($this->currentPath->getPath($request)); } } diff --git a/core/modules/system/src/PathBasedBreadcrumbBuilder.php b/core/modules/system/src/PathBasedBreadcrumbBuilder.php index c63f9e4..9af2638 100644 --- a/core/modules/system/src/PathBasedBreadcrumbBuilder.php +++ b/core/modules/system/src/PathBasedBreadcrumbBuilder.php @@ -14,7 +14,7 @@ use Drupal\Core\Controller\TitleResolverInterface; use Drupal\Core\Link; use Drupal\Core\ParamConverter\ParamNotConvertedException; -use Drupal\Core\Path\CurrentPath; +use Drupal\Core\Path\CurrentPathStack; use Drupal\Core\PathProcessor\InboundPathProcessorInterface; use Drupal\Core\Routing\RequestContext; use Drupal\Core\Routing\RouteMatch; @@ -100,10 +100,10 @@ class PathBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface { * The title resolver service. * @param \Drupal\Core\Session\AccountInterface $current_user * The current user object. - * @param \Drupal\Core\Path\CurrentPath $current_path + * @param \Drupal\Core\Path\CurrentPathStack $current_path * The current path. */ - public function __construct(RequestContext $context, AccessManagerInterface $access_manager, RequestMatcherInterface $router, InboundPathProcessorInterface $path_processor, ConfigFactoryInterface $config_factory, TitleResolverInterface $title_resolver, AccountInterface $current_user, CurrentPath $current_path) { + public function __construct(RequestContext $context, AccessManagerInterface $access_manager, RequestMatcherInterface $router, InboundPathProcessorInterface $path_processor, ConfigFactoryInterface $config_factory, TitleResolverInterface $title_resolver, AccountInterface $current_user, CurrentPathStack $current_path) { $this->context = $context; $this->accessManager = $access_manager; $this->router = $router; @@ -195,7 +195,7 @@ protected function getRequestForPath($path, array $exclude) { // This resolves to the front page, which we already add. return NULL; } - $this->currentPath->setPath($processed, $request); + $this->currentPath->setPath('/' . $processed, $request); // Attempt to match this path to provide a fully built request. try { $request->attributes->add($this->router->matchRequest($request)); diff --git a/core/modules/system/src/Plugin/Condition/RequestPath.php b/core/modules/system/src/Plugin/Condition/RequestPath.php index 85b57fe..a309c58 100644 --- a/core/modules/system/src/Plugin/Condition/RequestPath.php +++ b/core/modules/system/src/Plugin/Condition/RequestPath.php @@ -11,7 +11,7 @@ use Drupal\Core\Condition\ConditionPluginBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Path\AliasManagerInterface; -use Drupal\Core\Path\CurrentPath; +use Drupal\Core\Path\CurrentPathStack; use Drupal\Core\Path\PathMatcherInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -52,7 +52,7 @@ class RequestPath extends ConditionPluginBase implements ContainerFactoryPluginI /** * The current path. * - * @var \Drupal\Core\Path\CurrentPath + * @var \Drupal\Core\Path\CurrentPathStack */ protected $currentPath; @@ -65,7 +65,7 @@ class RequestPath extends ConditionPluginBase implements ContainerFactoryPluginI * The path matcher service. * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * The request stack. - * @param \Drupal\Core\Path\CurrentPath $current_path + * @param \Drupal\Core\Path\CurrentPathStack $current_path * The current path. * @param array $configuration * A configuration array containing information about the plugin instance. @@ -74,7 +74,7 @@ class RequestPath extends ConditionPluginBase implements ContainerFactoryPluginI * @param array $plugin_definition * The plugin implementation definition. */ - public function __construct(AliasManagerInterface $alias_manager, PathMatcherInterface $path_matcher, RequestStack $request_stack, CurrentPath $current_path, array $configuration, $plugin_id, array $plugin_definition) { + public function __construct(AliasManagerInterface $alias_manager, PathMatcherInterface $path_matcher, RequestStack $request_stack, CurrentPathStack $current_path, array $configuration, $plugin_id, array $plugin_definition) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->aliasManager = $alias_manager; $this->pathMatcher = $path_matcher; @@ -153,7 +153,7 @@ public function evaluate() { $request = $this->requestStack->getCurrentRequest(); // Compare the lowercase path alias (if any) and internal path. - $path = $this->currentPath->getPath($request); + $path = trim($this->currentPath->getPath($request), '/'); $path_alias = Unicode::strtolower($this->aliasManager->getAliasByPath($path)); return $this->pathMatcher->matchPath($path_alias, $pages) || (($path != $path_alias) && $this->pathMatcher->matchPath($path, $pages)); diff --git a/core/modules/system/src/Tests/Plugin/Condition/RequestPathTest.php b/core/modules/system/src/Tests/Plugin/Condition/RequestPathTest.php index e3cb884..45011f8 100644 --- a/core/modules/system/src/Tests/Plugin/Condition/RequestPathTest.php +++ b/core/modules/system/src/Tests/Plugin/Condition/RequestPathTest.php @@ -7,7 +7,7 @@ namespace Drupal\system\Tests\Plugin\Condition; -use Drupal\Core\Path\CurrentPath; +use Drupal\Core\Path\CurrentPathStack; use Drupal\simpletest\KernelTestBase; use Drupal\system\Tests\Routing\MockAliasManager; use Symfony\Component\HttpFoundation\Request; @@ -52,7 +52,7 @@ class RequestPathTest extends KernelTestBase { /** * The current path. * - * @var \Drupal\Core\Path\CurrentPath|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Path\CurrentPathStack|\PHPUnit_Framework_MockObject_MockObject */ protected $currentPath; @@ -74,7 +74,7 @@ protected function setUp() { $this->requestStack = new RequestStack(); $this->container->set('request_stack', $this->requestStack); - $this->currentPath = new CurrentPath($this->requestStack); + $this->currentPath = new CurrentPathStack($this->requestStack); $this->container->set('path.current', $this->currentPath); } @@ -101,7 +101,7 @@ public function testConditions() { $this->assertEqual($condition->summary(), 'Return true on the following pages: my/pass/page, my/pass/page2, foo', 'The condition summary matches for a standard path'); // Test an aliased path. - $this->currentPath->setPath('my/aliased/page', $request); + $this->currentPath->setPath('/my/aliased/page', $request); $this->requestStack->pop(); $this->requestStack->push($request); @@ -112,7 +112,7 @@ public function testConditions() { // Test a wildcard path. $this->aliasManager->addAlias('my/pass/page3', 'my/pass/page3'); - $this->currentPath->setPath('my/pass/page3', $request); + $this->currentPath->setPath('/my/pass/page3', $request); $this->requestStack->pop(); $this->requestStack->push($request); @@ -124,7 +124,7 @@ public function testConditions() { // Test a missing path. $this->requestStack->pop(); $this->requestStack->push($request); - $this->currentPath->setPath('my/fail/page4', $request); + $this->currentPath->setPath('/my/fail/page4', $request); $condition->setConfig('pages', 'my/pass/*'); diff --git a/core/modules/system/src/Tests/Routing/RouteProviderTest.php b/core/modules/system/src/Tests/Routing/RouteProviderTest.php index d74fbd5..080936b 100644 --- a/core/modules/system/src/Tests/Routing/RouteProviderTest.php +++ b/core/modules/system/src/Tests/Routing/RouteProviderTest.php @@ -8,7 +8,7 @@ namespace Drupal\system\Tests\Routing; use Drupal\Core\KeyValueStore\KeyValueMemoryFactory; -use Drupal\Core\Path\CurrentPath; +use Drupal\Core\Path\CurrentPathStack; use Drupal\Core\State\State; use Drupal\simpletest\KernelTestBase; use Symfony\Component\HttpFoundation\Request; @@ -54,7 +54,7 @@ class RouteProviderTest extends KernelTestBase { /** * The current path. * - * @var \Drupal\Core\Path\CurrentPath + * @var \Drupal\Core\Path\CurrentPathStack */ protected $currentPath; @@ -63,7 +63,7 @@ protected function setUp() { $this->fixtures = new RoutingFixtures(); $this->routeBuilder = new NullRouteBuilder(); $this->state = new State(new KeyValueMemoryFactory()); - $this->currentPath = new CurrentPath(new RequestStack()); + $this->currentPath = new CurrentPathStack(new RequestStack()); } protected function tearDown() { @@ -368,7 +368,7 @@ function testCurrentPath() { $dumper->dump(); $request = Request::create('/path/one', 'GET'); - $this->currentPath->setPath('path/two', $request); + $this->currentPath->setPath('/path/two', $request); $routes_by_pattern = $provider->getRoutesByPattern('/path/two'); $routes = $provider->getRouteCollectionForRequest($request); diff --git a/core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php b/core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php index dcbdf3b..68e1abf 100644 --- a/core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php +++ b/core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php @@ -79,7 +79,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase { /** * The mocked current path. * - * @var \Drupal\Core\Path\CurrentPath|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Path\CurrentPathStack|\PHPUnit_Framework_MockObject_MockObject */ protected $currentPath; @@ -101,7 +101,7 @@ protected function setUp() { $this->accessManager = $this->getMock('\Drupal\Core\Access\AccessManagerInterface'); $this->titleResolver = $this->getMock('\Drupal\Core\Controller\TitleResolverInterface'); $this->currentUser = $this->getMock('Drupal\Core\Session\AccountInterface'); - $this->currentPath = $this->getMockBuilder('Drupal\Core\Path\CurrentPath') + $this->currentPath = $this->getMockBuilder('Drupal\Core\Path\CurrentPathStack') ->disableOriginalConstructor() ->getMock(); diff --git a/core/modules/views/src/Controller/ViewAjaxController.php b/core/modules/views/src/Controller/ViewAjaxController.php index 177e586..536e10a 100644 --- a/core/modules/views/src/Controller/ViewAjaxController.php +++ b/core/modules/views/src/Controller/ViewAjaxController.php @@ -12,7 +12,7 @@ use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\Core\Path\CurrentPath; +use Drupal\Core\Path\CurrentPathStack; use Drupal\Core\Render\RendererInterface; use Drupal\views\Ajax\ScrollTopCommand; use Drupal\views\Ajax\ViewAjaxResponse; @@ -51,7 +51,7 @@ class ViewAjaxController implements ContainerInjectionInterface { /** * The current path. * - * @var \Drupal\Core\Path\CurrentPath + * @var \Drupal\Core\Path\CurrentPathStack */ protected $currentPath; @@ -64,10 +64,10 @@ class ViewAjaxController implements ContainerInjectionInterface { * The factory to load a view executable with. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer. - * @param \Drupal\Core\Path\CurrentPath $current_path + * @param \Drupal\Core\Path\CurrentPathStack $current_path * The current path. */ - public function __construct(EntityStorageInterface $storage, ViewExecutableFactory $executable_factory, RendererInterface $renderer, CurrentPath $current_path) { + public function __construct(EntityStorageInterface $storage, ViewExecutableFactory $executable_factory, RendererInterface $renderer, CurrentPathStack $current_path) { $this->storage = $storage; $this->executableFactory = $executable_factory; $this->renderer = $renderer; @@ -135,7 +135,7 @@ public function ajaxView(Request $request) { $response->setView($view); // Fix the current path for paging. if (!empty($path)) { - $this->currentPath->setPath($path, $request); + $this->currentPath->setPath('/' . $path, $request); } // Add all POST data, because AJAX is always a post and many things, diff --git a/core/modules/views/src/Plugin/views/argument_default/Raw.php b/core/modules/views/src/Plugin/views/argument_default/Raw.php index 7a96512..4239c50 100644 --- a/core/modules/views/src/Plugin/views/argument_default/Raw.php +++ b/core/modules/views/src/Plugin/views/argument_default/Raw.php @@ -9,7 +9,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Path\AliasManagerInterface; -use Drupal\Core\Path\CurrentPath; +use Drupal\Core\Path\CurrentPathStack; use Drupal\views\Plugin\CacheablePluginInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -36,7 +36,7 @@ class Raw extends ArgumentDefaultPluginBase implements CacheablePluginInterface /** * The current path. * - * @var \Drupal\Core\Path\CurrentPath + * @var \Drupal\Core\Path\CurrentPathStack */ protected $currentPath; @@ -51,10 +51,10 @@ class Raw extends ArgumentDefaultPluginBase implements CacheablePluginInterface * The plugin implementation definition. * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager * The alias manager. - * @param \Drupal\Core\Path\CurrentPath $current_path + * @param \Drupal\Core\Path\CurrentPathStack $current_path * The current path. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, AliasManagerInterface $alias_manager, CurrentPath $current_path) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, AliasManagerInterface $alias_manager, CurrentPathStack $current_path) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->aliasManager = $alias_manager; @@ -103,7 +103,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { } public function getArgument() { - $path = $this->currentPath->getPath($this->view->getRequest()); + $path = trim($this->currentPath->getPath($this->view->getRequest()), '/'); if ($this->options['use_alias']) { $path = $this->aliasManager->getAliasByPath($path); } diff --git a/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php b/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php index 3493a74..61e475b 100644 --- a/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php +++ b/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php @@ -43,7 +43,7 @@ class ViewAjaxControllerTest extends UnitTestCase { /** * The mocked current path. * - * @var \Drupal\Core\Path\CurrentPath|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Path\CurrentPathStack|\PHPUnit_Framework_MockObject_MockObject */ protected $currentPath; @@ -59,7 +59,7 @@ protected function setUp() { $elements['#attached'] = []; return isset($elements['#markup']) ? $elements['#markup'] : ''; })); - $this->currentPath = $this->getMockBuilder('Drupal\Core\Path\CurrentPath') + $this->currentPath = $this->getMockBuilder('Drupal\Core\Path\CurrentPathStack') ->disableOriginalConstructor() ->getMock(); diff --git a/core/modules/views/tests/src/Unit/Plugin/argument_default/RawTest.php b/core/modules/views/tests/src/Unit/Plugin/argument_default/RawTest.php index 0f9593b..f50b928 100644 --- a/core/modules/views/tests/src/Unit/Plugin/argument_default/RawTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/argument_default/RawTest.php @@ -7,7 +7,7 @@ namespace Drupal\Tests\views\Unit\Plugin\argument_default; -use Drupal\Core\Path\CurrentPath; +use Drupal\Core\Path\CurrentPathStack; use Drupal\Tests\UnitTestCase; use Drupal\views\Plugin\views\argument_default\Raw; use Symfony\Component\HttpFoundation\Request; @@ -31,10 +31,10 @@ public function testGetArgument() { $display_plugin = $this->getMockBuilder('Drupal\views\Plugin\views\display\DisplayPluginBase') ->disableOriginalConstructor() ->getMock(); - $current_path = new CurrentPath(new RequestStack()); + $current_path = new CurrentPathStack(new RequestStack()); $request = new Request(); - $current_path->setPath('test/example', $request); + $current_path->setPath('/test/example', $request); $view->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request));