diff -u b/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php --- b/core/lib/Drupal/Core/Routing/UrlGenerator.php +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php @@ -309,7 +309,9 @@ $name = $this->getRouteDebugMessage($name); $this->processRoute($name, $route, $parameters, $generated_url); $path = $this->getInternalPathFromRoute($name, $route, $parameters, $query_params); - $options['route_name'] = $name; + // Outbound path processors might need the route object for the path, e.g. + // to get the path pattern. + $options['route'] = $route; $path = $this->processPath($path, $options, $generated_url); if (!empty($options['prefix'])) { diff -u b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php --- b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php @@ -13,13 +13,13 @@ use Drupal\Core\PathProcessor\OutboundPathProcessorInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Render\BubbleableMetadata; -use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\Url; use Drupal\language\LanguageNegotiationMethodBase; use Drupal\language\LanguageSwitcherInterface; use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Route as SymfonyRoute; /** * Class for identifying the content translation language. @@ -61,11 +61,11 @@ protected $hasHigherLanguageNegotiationOrderResult; /** - * The route provider. + * Static cache of outbound routes per request. * - * @var \Symfony\Cmf\Component\Routing\RouteProviderInterface; + * @var \SplObjectStorage */ - protected $routeProvider; + protected $paths; /** * The entity manager. @@ -75,22 +75,12 @@ protected $entityManager; /** - * Static cache of outbound routes per request. - * - * @var \SplObjectStorage - */ - protected $paths; - - /** * Constructs a new LanguageNegotiationContentEntity instance. * - * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider - * The route provider. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. */ - public function __construct(RouteProviderInterface $route_provider, EntityManagerInterface $entity_manager) { - $this->routeProvider = $route_provider; + public function __construct(EntityManagerInterface $entity_manager) { $this->entityManager = $entity_manager; $this->paths = new \SplObjectStorage(); } @@ -99,7 +89,7 @@ * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static($container->get('router.route_provider'), $container->get('entity.manager')); + return new static($container->get('entity.manager')); } /** @@ -121,7 +111,7 @@ // url. // First, check if processing conditions are met. - if (!($request && !empty($options['route_name']) && $this->hasHigherLanguageNegotiationOrder() && $this->meetsContentEntityRoutesCondition($options['route_name'], $request))) { + if (!($request && !empty($options['route']) && $this->hasHigherLanguageNegotiationOrder() && $this->meetsContentEntityRoutesCondition($options['route'], $request))) { return $path; } @@ -232,31 +222,31 @@ * Requirements: currently being on an content entity route and processing * outbound url pointing to the same content entity. * - * @param string $outbound_route_name - * The route name for the current outbound url being processed. + * @param \Symfony\Component\Routing\Route $outbound_route + * The route object for the current outbound url being processed. * @param \Symfony\Component\HttpFoundation\Request $request * The HttpRequest object representing the current request. * * @return bool * TRUE if the content entity route condition is met, FALSE otherwise. */ - protected function meetsContentEntityRoutesCondition($outbound_route_name, Request $request) { + protected function meetsContentEntityRoutesCondition(SymfonyRoute $outbound_route, Request $request) { + $outbound_path_pattern = $outbound_route->getPath(); $storage = isset($this->paths[$request]) ? $this->paths[$request] : []; - if (!isset($storage[$outbound_route_name])) { - $storage[$outbound_route_name] = FALSE; + if (!isset($storage[$outbound_path_pattern])) { + $storage[$outbound_path_pattern] = FALSE; // Check if the outbound route points to the current entity. if ($content_entity_type_id_for_current_route = $this->getContentEntityTypeIdForCurrentRequest($request)) { - $outbound_route_path = $this->routeProvider->getRouteByName($outbound_route_name)->getPath(); - if (!empty($this->getContentEntityPaths()[$outbound_route_path]) && $content_entity_type_id_for_current_route == $this->getContentEntityPaths()[$outbound_route_path]) { - $storage[$outbound_route_name] = TRUE; + if (!empty($this->getContentEntityPaths()[$outbound_path_pattern]) && $content_entity_type_id_for_current_route == $this->getContentEntityPaths()[$outbound_path_pattern]) { + $storage[$outbound_path_pattern] = TRUE; } } $this->paths[$request] = $storage; } - return $storage[$outbound_route_name]; + return $storage[$outbound_path_pattern]; } /** @@ -271,8 +261,8 @@ protected function getContentEntityTypeIdForCurrentRequest(Request $request) { $content_entity_type_id_for_current_route = ''; - if ($current_route_name = $request->attributes->get(RouteObjectInterface::ROUTE_NAME)) { - $current_route_path = $this->routeProvider->getRouteByName($current_route_name)->getPath(); + if ($current_route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT)) { + $current_route_path = $current_route->getPath(); $content_entity_type_id_for_current_route = isset($this->getContentEntityPaths()[$current_route_path]) ? $this->getContentEntityPaths()[$current_route_path] : ''; } only in patch2: unchanged: --- a/core/lib/Drupal/Core/PathProcessor/OutboundPathProcessorInterface.php +++ b/core/lib/Drupal/Core/PathProcessor/OutboundPathProcessorInterface.php @@ -21,8 +21,27 @@ * @param string $path * The path to process, with a leading slash. * @param array $options - * An array of options such as would be passed to the generator's - * generateFromRoute() method. + * (optional) An associative array of additional options, with the following + * elements: + * - 'query': An array of query key/value-pairs (without any URL-encoding) + * to append to the URL. + * - 'fragment': A fragment identifier (named anchor) to append to the URL. + * Do not include the leading '#' character. + * - 'absolute': Defaults to FALSE. Whether to force the output to be an + * absolute link (beginning with http:). Useful for links that will be + * displayed outside the site, such as in an RSS feed. + * - 'language': An optional language object used to look up the alias + * for the URL. If $options['language'] is omitted, it defaults to the + * current language for the language type LanguageInterface::TYPE_URL. + * - 'https': Whether this URL should point to a secure location. If not + * defined, the current scheme is used, so the user stays on HTTP or HTTPS + * 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. + * - 'route': The route object for the given path. It will be set by + * \Drupal\Core\Routing\UrlGenerator::generateFromRoute(). * @param \Symfony\Component\HttpFoundation\Request $request * The HttpRequest object representing the current request. * @param \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata