diff --git a/core/includes/common.inc b/core/includes/common.inc index 7ad06a6..ff9d1a9 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3525,7 +3525,7 @@ function drupal_pre_render_link($element) { } if (isset($element['#route_name'])) { - $element['#markup'] = Drupal::linkGenerator()->link($element['#title'], $element['#route_name'], $element['#parameters'], $element['#options']); + $element['#markup'] = Drupal::linkGenerator()->link($element['#title'], $element['#route_name'], $element['#route_parameters'], $element['#options']); } else { $element['#markup'] = l($element['#title'], $element['#href'], $element['#options']); diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 11e73e1..e9ed33d 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -374,7 +374,7 @@ public static function urlGenerator() { /** * Returns the link generator service. * - * @return \Drupal\Core\Utility\LinkGenerator + * @return \Drupal\Core\Utility\LinkGeneratorInterface */ public static function linkGenerator() { return static::$container->get('link_generator'); diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php index 402caa6..f904553 100644 --- a/core/lib/Drupal/Core/Routing/UrlGenerator.php +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php @@ -21,7 +21,7 @@ use Drupal\Core\PathProcessor\OutboundPathProcessorInterface; /** - * A Generator creates URL strings based on a specified route. + * Defines an interface which generates a link with route names and parameters. */ class UrlGenerator extends ProviderBasedGenerator implements PathBasedGeneratorInterface { diff --git a/core/lib/Drupal/Core/Utility/LinkGenerator.php b/core/lib/Drupal/Core/Utility/LinkGenerator.php index 1d56bfa..3edce86 100644 --- a/core/lib/Drupal/Core/Utility/LinkGenerator.php +++ b/core/lib/Drupal/Core/Utility/LinkGenerator.php @@ -12,9 +12,13 @@ use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManager; use Drupal\Core\Template\Attribute; +use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +/** + * Provides a class which generates a link with route names and parameters. + */ class LinkGenerator implements LinkGeneratorInterface { /** @@ -80,7 +84,7 @@ public function setRequest(Request $request) { // Because this service is called very often we statically cache values that // require an extra function call. $this->active = array( - 'route_name' => $this->request->attributes->get('_route'), + 'route_name' => $this->request->attributes->get(RouteObjectInterface::ROUTE_NAME), 'language' => $this->languageManager->getLanguage(Language::TYPE_URL)->id, 'parameters' => (array) $this->request->attributes->get('_raw_variables') + (array) $this->request->query->all(), ); diff --git a/core/lib/Drupal/Core/Utility/LinkGeneratorInterface.php b/core/lib/Drupal/Core/Utility/LinkGeneratorInterface.php index db5b2a8..dc79ff4 100644 --- a/core/lib/Drupal/Core/Utility/LinkGeneratorInterface.php +++ b/core/lib/Drupal/Core/Utility/LinkGeneratorInterface.php @@ -7,6 +7,9 @@ namespace Drupal\Core\Utility; +/** + * Defines an interface for a service which generates a link out of a + */ interface LinkGeneratorInterface { /** diff --git a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php index c9cd301..f82e5f1 100644 --- a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php @@ -10,6 +10,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Utility\LinkGenerator; use Drupal\Tests\UnitTestCase; + use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; /** @@ -226,16 +227,6 @@ public function testLinkActive() { array('test_route_3', array(), FALSE, '/test-route-3'), array('test_route_3', array(), FALSE, '/test-route-3'), ))); - $this->urlGenerator->expects($this->exactly(6)) - ->method('getPathFromRoute') - ->will($this->returnValueMap(array( - array('test_route_1', array(), 'test-route-1'), - array('test_route_1', array(), 'test-route-1'), - array('test_route_1', array(), 'test-route-1'), - array('test_route_1', array(), 'test-route-1'), - array('test_route_3', array(), 'test-route-3'), - array('test_route_3', array(), 'test-route-3'), - ))); $this->moduleHandler->expects($this->exactly(6)) ->method('alter'); @@ -252,7 +243,7 @@ public function testLinkActive() { ), $result); // Render a link with the same path as the current path. - $request = new Request(array(), array(), array('system_path' => 'test-route-1')); + $request = new Request(array(), array(), array('system_path' => 'test-route-1', RouteObjectInterface::ROUTE_NAME => 'test_route_1')); $this->linkGenerator->setRequest($request); $result = $this->linkGenerator->link('Test', 'test_route_1'); $this->assertTag(array( @@ -281,7 +272,7 @@ public function testLinkActive() { ), $result); // Render a link with the same path and query parameter as the current path. - $request = new Request(array('value' => 'example_1'), array(), array('system_path' => 'test-route-3')); + $request = new Request(array('value' => 'example_1'), array(), array('system_path' => 'test-route-3', RouteObjectInterface::ROUTE_NAME => 'test_route_3')); $parameters = $request->query->all(); $this->linkGenerator->setRequest($request); $result = $this->linkGenerator->link(