Problem/Motivation

If you add a multilingual menu link with internal:/some-path-alias uri in a menu, clearing the cache populates cache_data record with an incorrect RouteCollection routes.

For example if I have a Finnish node with path alias /broken-url-alias-test and manually add it (with the path, not with entity:node/X uri) to the menu and set menu link language to Finnish, clearing the cache generates the following route collection for cid = route:/broken-url-alias-test::

a:3:{s:4:"path";s:17:"/broken-url-alias";s:5:"query";a:0:{}s:6:"routes";O:41:"Symfony\Component\Routing\RouteCollection":2:{s:49:" Symfony\Component\Routing\RouteCollection routes";a:0:{}s:52:" Symfony\Component\Routing\RouteCollection resources";a:0:{}}}

and visiting the /broken-url-alias path will obviously result in 404 error.

If you manually delete the cache record, add anything to the url (like /broken-url-alias-test?1) or clear caches via ui when the ui language is same as the menu link language (fi.d8.local/admin/config/development/performance) it seems to work just fine.

Steps to Reproduce

1. Install all modules in Multilingual (language, locale, config_translation, content_translation)
2. Add Finnish language (or any other language)
3. Enable URL (domain) detection method, set language specific domains (fi.d8.local, d8.local etc.)
4. Enable "Content" and "Custom menu link" translation (/admin/config/regional/content-language)
5. Create a new (Finnish) node with an url alias (/broken-url-alias-test)
6. Add a new menu link to the footer menu with /broken-url-alias-test link and set language to Finnish
7. Flush caches and go to fi.d8.local/broken-url-alias-test

I'm not sure if this is specific to "Domain" language detection as this seems to sometimes happen with path prefix as well.

CommentFileSizeAuthor
#5 2852303-5.patch3.05 KBleksat
#3 2852303-3.patch872 bytesleksat

Comments

tuutti created an issue. See original summary.

leksat’s picture

This probably caused not by menu links, but by the routing system in general - it seems like it does not count domains when caches routes.

My steps to reproduce:
- clean drupal 8.3.x (67a934e) installation, website with en. and ru. subdomains, domain based language detection
- create en node with url path alias "/test-en" => node is available at "en.example.com/test-en"
- clear caches
- access "ru.example.com/test-en" => 404
- access "en.example.com/test-en" => also 404

leksat’s picture

Status: Active » Needs review
StatusFileSize
new872 bytes

Status: Needs review » Needs work

The last submitted patch, 3: 2852303-3.patch, failed testing.

leksat’s picture

Status: Needs work » Needs review
StatusFileSize
new3.05 KB
leksat’s picture

@tuutti can you check if patch #5 fixes the bug for you?

tuutti’s picture

This probably caused not by menu links, but by the routing system in general - it seems like it does not count domains when caches routes.

You are right. It was easier to demonstrate this with menu links because the route cache for menu links will be re-populated during the cache clear.

@tuutti can you check if patch #5 fixes the bug for you?

It does, thank you!

This however will cause at least two different issues:

  1. This will render pre-caching menu link routes pretty much useless because Drupal does not necessarily know the correct hostname during the cache clear
  2. A lot duplicate cache entries will be generated if have multiple domains to access the site (like domain_access), but not sure if this is really a problem
leksat’s picture

@tuutti,

This will render pre-caching menu link routes pretty much useless because Drupal does not necessarily know the correct hostname during the cache clear

i'm not sure what you mean... Can you point me to the code where this happens?

tuutti’s picture

i'm not sure what you mean... Can you point me to the code where this happens?

\Drupal\Core\Routing\RouteProvider::getRouteCollectionForRequest().

I think it is initialized by \Drupal\Core\Menu\MenuLinkManager::rebuild() which eventually will call getRouteCollectionForRequest() for every menu link.

You can confirm this by placing some menu links and clearing the cache and then query cache data table.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

hctom’s picture

Sorry to crosspost a little, but I just created another issue that might have the same root cause: #2915190: Menu links losing active trail when not edited in path alias language (sorry for the bad title, but I did not really know how to title it because of its complexicity, hehe). Currently I only added detailed steps to reproduce losing the menu active trail when using aliased paths as menu links. Perhaps someone might have a look and see if this is related or gives you some more information/ideas on what happens here.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

berdir’s picture

Status: Needs review » Closed (duplicate)