diff --git a/core/core.services.yml b/core/core.services.yml index bd2f2c1e..121e5f6a 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1268,10 +1268,16 @@ services: tags: - { name: service_collector, tag: path_processor_inbound, call: addInbound } - { name: service_collector, tag: path_processor_outbound, call: addOutbound } + alias_processor_manager: + class: Drupal\Core\PathProcessor\AliasProcessorManager + tags: + - { name: service_collector, tag: alias_processor_inbound, call: addInbound } + - { name: service_collector, tag: alias_processor_outbound, call: addInbound } path_processor_decode: class: Drupal\Core\PathProcessor\PathProcessorDecode tags: - { name: path_processor_inbound, priority: 1000 } + - { name: alias_processor_inbound, priority: 1000 } path_processor_front: class: Drupal\Core\PathProcessor\PathProcessorFront tags: @@ -1288,7 +1294,7 @@ services: tags: - { name: path_processor_inbound, priority: 100 } - { name: path_processor_outbound, priority: 300 } - arguments: ['@path.alias_manager'] + arguments: ['@path.alias_manager', '@alias_processor_manager'] route_processor_csrf: class: Drupal\Core\Access\RouteProcessorCsrf tags: diff --git a/core/lib/Drupal/Core/PathProcessor/AliasProcessorManager.php b/core/lib/Drupal/Core/PathProcessor/AliasProcessorManager.php new file mode 100644 index 00000000..710a92e8 --- /dev/null +++ b/core/lib/Drupal/Core/PathProcessor/AliasProcessorManager.php @@ -0,0 +1,38 @@ +getPathInfo(); + return parent::processInbound($alias_match, $request); + } + +} \ No newline at end of file diff --git a/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php b/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php index b85737f3..be2c2b28 100644 --- a/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php +++ b/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php @@ -19,21 +19,44 @@ class PathProcessorAlias implements InboundPathProcessorInterface, OutboundPathP protected $aliasManager; /** + * An alias processor manager to compute the alias to look up. + * + * @var \Drupal\Core\PathProcessor\InboundPathProcessorInterface + */ + protected $aliasProcessorManager; + + /** * Constructs a PathProcessorAlias object. * * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager * An alias manager for looking up the system path. + * @param \Drupal\Core\PathProcessor\InboundPathProcessorInterface $alias_processor_manager + * An inbound path processor for processing the inbound path. */ - public function __construct(AliasManagerInterface $alias_manager) { + public function __construct(AliasManagerInterface $alias_manager, InboundPathProcessorInterface $alias_processor_manager) { $this->aliasManager = $alias_manager; + $this->aliasProcessorManager = $alias_processor_manager; } /** * {@inheritdoc} */ public function processInbound($path, Request $request) { - $path = $this->aliasManager->getPathByAlias($path); - return $path; + $alias = $this->aliasProcessorManager->processInbound($path, $request); + // Allow the query string to be a part of an alias match. + if (!empty($request->server->get('QUERY_STRING'))) { + $alias .= '?' . $request->server->get('QUERY_STRING'); + } + // @TODO Match parameters in any order; would require AliasStorageInterface + // changes. + $de_aliased = $this->aliasManager->getPathByAlias($alias); + + if ($de_aliased !== $alias) { + return $de_aliased; + } + else { + return $path; + } } /** diff --git a/core/modules/language/src/LanguageServiceProvider.php b/core/modules/language/src/LanguageServiceProvider.php index 4060f75d..eb350984 100644 --- a/core/modules/language/src/LanguageServiceProvider.php +++ b/core/modules/language/src/LanguageServiceProvider.php @@ -30,7 +30,9 @@ public function register(ContainerBuilder $container) { $container->register('path_processor_language', 'Drupal\language\HttpKernel\PathProcessorLanguage') ->addTag('path_processor_inbound', ['priority' => 300]) + ->addTag('alias_processor_inbound', array('priority' => 300)) ->addTag('path_processor_outbound', ['priority' => 100]) + ->addTag('alias_processor_outbound', array('priority' => 100)) ->addArgument(new Reference('config.factory')) ->addArgument(new Reference('language_manager')) ->addArgument(new Reference('language_negotiator')) diff --git a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorAliasTest.php b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorAliasTest.php index 0473d79d..d3a92eea 100644 --- a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorAliasTest.php +++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorAliasTest.php @@ -22,6 +22,13 @@ class PathProcessorAliasTest extends UnitTestCase { protected $aliasManager; /** + * The mocked alias processor manager. + * + * @var \Drupal\Core\PathProcessor\InboundPathProcessorInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $aliasProcessorManager; + + /** * The tested path processor. * * @var \Drupal\Core\PathProcessor\PathProcessorAlias @@ -30,7 +37,8 @@ class PathProcessorAliasTest extends UnitTestCase { protected function setUp() { $this->aliasManager = $this->getMock('Drupal\Core\Path\AliasManagerInterface'); - $this->pathProcessor = new PathProcessorAlias($this->aliasManager); + $this->aliasProcessorManager = $this->getMock('Drupal\Core\PathProcessor\AliasProcessorManager'); + $this->pathProcessor = new PathProcessorAlias($this->aliasManager, $this->aliasProcessorManager); } /** @@ -46,6 +54,10 @@ public function testProcessInbound() { ['url', NULL, 'url'], ])); + $this->aliasProcessorManager->expects($this->exactly(2)) + ->method('processInbound') + ->will($this->returnArgument(0)); + $request = Request::create('/urlalias'); $this->assertEquals('internal-url', $this->pathProcessor->processInbound('urlalias', $request)); $request = Request::create('/url'); diff --git a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php index 57dfbfa1..a3bde390 100644 --- a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php +++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php @@ -110,6 +110,11 @@ public function testProcessInbound() { ->method('getPathByAlias') ->will($this->returnValueMap($system_path_map)); + $alias_processor_manager = $this->getMock('Drupal\Core\PathProcessor\AliasProcessorManager'); + $alias_processor_manager->expects($this->any()) + ->method('processInbound') + ->will($this->returnArgument(0)); + // Create a stub config factory with all config settings that will be checked // during this test. $config_factory_stub = $this->getConfigFactoryStub( @@ -152,7 +157,7 @@ public function testProcessInbound() { ->getMock(); // Create the processors. - $alias_processor = new PathProcessorAlias($alias_manager); + $alias_processor = new PathProcessorAlias($alias_manager, $alias_processor_manager); $decode_processor = new PathProcessorDecode(); $front_processor = new PathProcessorFront($config_factory_stub); $language_processor = new PathProcessorLanguage($config_factory_stub, $this->languageManager, $negotiator, $current_user, $config_subscriber); diff --git a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php index 6c6d768a..131fb5fc 100644 --- a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php @@ -48,6 +48,13 @@ class UrlGeneratorTest extends UnitTestCase { protected $aliasManager; /** + * The mocked alias processor manager. + * + * @var \Drupal\Core\PathProcessor\InboundPathProcessorInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $aliasProcessorManager; + + /** * The mock route processor manager. * * @var \Drupal\Core\RouteProcessor\RouteProcessorManager|\PHPUnit_Framework_MockObject_MockObject @@ -153,6 +160,14 @@ protected function setUp() { $this->aliasManager = $alias_manager; + // Create an alias processor manager stub. + $alias_processor_manager = $this->getMock('Drupal\Core\PathProcessor\AliasProcessorManager'); + $alias_processor_manager->expects($this->any()) + ->method('processInbound') + ->will($this->returnArgument(0)); + + $this->aliasProcessorManager = $alias_processor_manager; + $this->requestStack = new RequestStack(); $request = Request::create('/some/path'); $this->requestStack->push($request); @@ -160,7 +175,7 @@ protected function setUp() { $this->context = new RequestContext(); $this->context->fromRequestStack($this->requestStack); - $processor = new PathProcessorAlias($this->aliasManager); + $processor = new PathProcessorAlias($this->aliasManager, $this->aliasProcessorManager); $processor_manager = new PathProcessorManager(); $processor_manager->addOutbound($processor, 1000); $this->processorManager = $processor_manager;