Commit 88a2fe6c authored by samuel.mortenson's avatar samuel.mortenson Committed by Samuel Mortenson

Issue #3052728 by samuel.mortenson, corneboele: System paths being prefixed...

Issue #3052728 by samuel.mortenson, corneboele: System paths being prefixed twice when default language has a prefix
parent d5550808
......@@ -58,7 +58,7 @@ class LanguagePathSubscriber implements EventSubscriberInterface {
if ($config['source'] === LanguageNegotiationUrl::CONFIG_PATH_PREFIX) {
foreach ($this->languageManager->getLanguages() as $language) {
$langcode = $language->getId();
if (isset($config['prefixes'][$langcode]) && !$language->isDefault()) {
if (!empty($config['prefixes'][$langcode])) {
$prefix = $this->joinPaths('/', $config['prefixes'][$langcode]);
$event->addPath($prefix, ['language_processed' => 'language_processed']);
foreach ($event->getPaths(TRUE) as $path => $metadata) {
......
......@@ -2,6 +2,8 @@
namespace Drupal\tome_static\EventSubscriber;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Url;
use Drupal\tome_static\Event\CollectPathsEvent;
......@@ -22,14 +24,24 @@ class RoutePathSubscriber implements EventSubscriberInterface {
*/
protected $routeProvider;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs the RoutePathSubscriber object.
*
* @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
* The route provider.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
*/
public function __construct(RouteProviderInterface $route_provider) {
public function __construct(RouteProviderInterface $route_provider, LanguageManagerInterface $language_manager) {
$this->routeProvider = $route_provider;
$this->languageManager = $language_manager;
}
/**
......@@ -39,9 +51,13 @@ class RoutePathSubscriber implements EventSubscriberInterface {
* The collect paths event.
*/
public function collectPaths(CollectPathsEvent $event) {
$language_none = $this->languageManager
->getLanguage(LanguageInterface::LANGCODE_NOT_APPLICABLE);
foreach ($this->routeProvider->getAllRoutes() as $route_name => $route) {
try {
$url = Url::fromRoute($route_name);
$url = Url::fromRoute($route_name, [], [
'language' => $language_none,
]);
$path = $url->toString();
if ($path && $url->access()) {
$event->addPath(parse_url($path, PHP_URL_PATH));
......
......@@ -112,6 +112,30 @@ class StaticGeneratorTest extends TestBase {
'/french/tome-test/oembed-page',
'_entity:user:en:0',
], $static->getPaths());
$this->config('language.negotiation')->set('url.prefixes', [
'en' => 'english',
'fr' => 'french',
])->save();
$this->assertUnsortedEquals([
'/',
'/tome-test/complex-page',
'/tome-test/oembed-page',
'/tome-test/page',
'/tome-test/pager-page',
'/english',
'/english/tome-test/complex-page',
'/english/tome-test/oembed-page',
'/english/tome-test/page',
'/english/tome-test/pager-page',
'/french',
'/french/tome-test/complex-page',
'/french/tome-test/oembed-page',
'/french/tome-test/page',
'/french/tome-test/pager-page',
'_entity:user:en:0',
], $static->getPaths());
}
/**
......
......@@ -9,7 +9,7 @@ services:
- { name: cache.bin }
tome_static.route_path_subscriber:
class: Drupal\tome_static\EventSubscriber\RoutePathSubscriber
arguments: ['@router.route_provider']
arguments: ['@router.route_provider', '@language_manager']
tags:
- { name: event_subscriber }
tome_static.entity_path_subscriber:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment