diff --git a/core/core.services.yml b/core/core.services.yml index fa3b1d4..3760abb 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -497,7 +497,7 @@ services: - [setContext, ['@?router.request_context']] url_generator: class: Drupal\Core\Routing\CachedUrlGenerator - arguments: ['@url_generator.uncached', '@cache.url_generator', '@language_manager'] + arguments: ['@url_generator.uncached', '@cache.url_generator', '@language_manager', '@router.route_provider'] unrouted_url_assembler: class: Drupal\Core\Utility\UnroutedUrlAssembler arguments: ['@request_stack', '@config.factory' ] diff --git a/core/lib/Drupal/Core/Routing/CachedUrlGenerator.php b/core/lib/Drupal/Core/Routing/CachedUrlGenerator.php index b5583d8..0bb9a47 100644 --- a/core/lib/Drupal/Core/Routing/CachedUrlGenerator.php +++ b/core/lib/Drupal/Core/Routing/CachedUrlGenerator.php @@ -11,6 +11,7 @@ use Drupal\Core\DestructableInterface; use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManagerInterface; +use Symfony\Cmf\Component\Routing\RouteProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\RequestContext as SymfonyRequestContext; @@ -72,6 +73,13 @@ class CachedUrlGenerator implements DestructableInterface, CachedUrlGeneratorInt const PATH_CACHE_PREFIX = 'path::'; /** + * The route provider. + * + * @var \Symfony\Cmf\Component\Routing\RouteProviderInterface + */ + protected $routeProvider; + + /** * Constructs a \Drupal\Core\Routing\CachedUrlGenerator. * * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator @@ -80,11 +88,14 @@ class CachedUrlGenerator implements DestructableInterface, CachedUrlGeneratorInt * The cache backend. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Symfony\Cmf\Component\Routing\RouteProviderInterface $route_provider + * The route provider. */ - public function __construct(UrlGeneratorInterface $url_generator, CacheBackendInterface $cache, LanguageManagerInterface $language_manager) { + public function __construct(UrlGeneratorInterface $url_generator, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, RouteProviderInterface $route_provider) { $this->urlGenerator = $url_generator; $this->cache = $cache; $this->languageManager = $language_manager; + $this->routeProvider = $route_provider; } /** @@ -111,8 +122,8 @@ protected function writeCache() { */ public function generate($name, $parameters = array(), $absolute = FALSE) { $options = array(); - // We essentially inline the implentation from the Drupal UrlGenerator - // and avoid setting $options so that we increase the liklihood of caching. + // We essentially inline the implementation from the Drupal UrlGenerator + // and avoid setting $options so that we increase the likelihood of caching. if ($absolute) { $options['absolute'] = $absolute; } @@ -138,8 +149,15 @@ public function generateFromRoute($name, $parameters = array(), $options = array // In some cases $name may be a Route object, rather than a string. $key = self::ROUTE_CACHE_PREFIX . hash('sha256', serialize($name) . serialize($options) . serialize($parameters)); if (!isset($this->cachedUrls[$key])) { - $this->cachedUrls[$key] = $this->urlGenerator->generateFromRoute($name, $parameters, $options); - $this->cacheNeedsWriting = TRUE; + $generated_url = $this->urlGenerator->generateFromRoute($name, $parameters, $options); + $route = $this->routeProvider->getRouteByName($name); + if ($route->hasOption('_cacheable') && !$route->getOption('_cacheable')) { + return $generated_url; + } + else { + $this->cachedUrls[$key] = $generated_url; + $this->cacheNeedsWriting = TRUE; + } } return $this->cachedUrls[$key]; } @@ -157,28 +175,6 @@ public function setRequest(Request $request) { if ($cached) { $this->cachedUrls = $cached->data; } - $this->urlGenerator->setRequest($request); - } - - /** - * {@inheritdoc} - */ - public function setBaseUrl($url) { - $this->urlGenerator->setBaseUrl($url); - } - - /** - * {@inheritdoc} - */ - public function setBasePath($path) { - $this->urlGenerator->setBasePath($path); - } - - /** - * {@inheritdoc} - */ - public function setScriptPath($path) { - $this->urlGenerator->setScriptPath($path); } /** diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml index b285bcf..0dd8264 100644 --- a/core/modules/system/system.routing.yml +++ b/core/modules/system/system.routing.yml @@ -364,9 +364,13 @@ system.theme_settings_theme: '': path: '' + options: + _cacheable: false '': path: '' + options: + _cacheable: false system.modules_uninstall: path: '/admin/modules/uninstall'