diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php index 5c5222b..1926d44 100644 --- a/core/lib/Drupal/Core/Routing/UrlGenerator.php +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php @@ -147,6 +147,7 @@ public function generate($name, $parameters = array(), $absolute = FALSE) { * {@inheritdoc} */ public function generateFromRoute($name, $parameters = array(), $options = array()) { + $options += array('prefix' => ''); $route = $this->getRoute($name); $this->processRoute($name, $route, $parameters); @@ -158,6 +159,12 @@ public function generateFromRoute($name, $parameters = array(), $options = array $path = $this->getInternalPathFromRoute($route, $parameters); $path = $this->processPath($path, $options); + if (!empty($options['prefix'])) { + $path = ltrim($path, '/'); + $prefix = empty($path) ? rtrim($options['prefix'], '/') : $options['prefix']; + $path = '/' . str_replace('%2F', '/', rawurlencode($prefix)) . $path; + } + $fragment = ''; if (isset($options['fragment'])) { if (($fragment = trim($options['fragment'])) != '') { diff --git a/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php index da96c8a..9b9bc4f 100644 --- a/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php +++ b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php @@ -134,6 +134,8 @@ public function getPathFromRoute($name, $parameters = array()); * respectively. TRUE enforces HTTPS and FALSE enforces HTTP. * - 'base_url': Only used internally by a path processor, for example, to * modify the base URL when a language dependent URL requires so. + * - 'prefix': Only used internally, to modify the path when a language + * dependent URL requires so. * * @return string * The generated URL for the given route. diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php index aee94fb..b76b1b1 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php @@ -142,7 +142,7 @@ public function processOutbound($path, &$options = array(), Request $request = N $config = $this->config->get('language.negotiation')->get('url'); if ($config['source'] == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) { if (is_object($options['language']) && !empty($config['prefixes'][$options['language']->getId()])) { - return empty($path) ? $config['prefixes'][$options['language']->getId()] : $config['prefixes'][$options['language']->getId()] . '/' . $path; + $options['prefix'] = $config['prefixes'][$options['language']->getId()] . '/'; } } elseif ($config['source'] == LanguageNegotiationUrl::CONFIG_DOMAIN) { diff --git a/core/modules/language/src/Tests/LanguageUrlRewritingTest.php b/core/modules/language/src/Tests/LanguageUrlRewritingTest.php index e9daa9a..f5b838a 100644 --- a/core/modules/language/src/Tests/LanguageUrlRewritingTest.php +++ b/core/modules/language/src/Tests/LanguageUrlRewritingTest.php @@ -50,6 +50,10 @@ protected function setUp() { // Enable URL language detection and selection. $edit = array('language_interface[enabled][language-url]' => 1); $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings')); + + // Check that drupalSettings contains path prefix. + $this->drupalGet('fr/admin/config/regional/language/detection'); + $this->assertRaw('"pathPrefix":"fr\/"', 'drupalSettings path prefix contains language code.'); } /** diff --git a/core/tests/Drupal/Tests/Core/Routing/RoutingFixtures.php b/core/tests/Drupal/Tests/Core/Routing/RoutingFixtures.php index 48071ae..ffbfb03 100644 --- a/core/tests/Drupal/Tests/Core/Routing/RoutingFixtures.php +++ b/core/tests/Drupal/Tests/Core/Routing/RoutingFixtures.php @@ -203,7 +203,7 @@ public function routingTableDefinition() { 'default' => '', ), 'access_callback' => array( - 'description' => 'The callback which determines the access to this router path. Defaults to user_access.', + 'description' => 'The callback which determines the access to this router path. Defaults to \Drupal\Core\Session\AccountInterface::hasPermission.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE,