- ๐บ๐ธUnited States recrit
I've found this to be a bigger issue when creating views with mixed translation links. Any views handler that extends
Drupal\views\Plugin\views\field\LinkBase
has this issue - entity view link, entity edit link, etc. They all use theLinkBase::checkUrlAccess()
which checks the URL access with$this->accessManager->checkNamedRoute($url->getRouteName(), $url->getRouteParameters(), $this->currentUser(), TRUE);
which ignores the language of the URL object and consequently checks the URL access using the current interface language.
Example: When on an admin view where the admin language is English and the views row entity URL is Spanish, the access check will check access for the English version of the route. This can cause very odd issues when the English translation has a published version, but the Spanish version is only in Draft. - ๐บ๐ธUnited States mlncn Minneapolis, MN, USA
Glad this is already marked major, not so glad there doesn't seem to be a clear path to fixingโ because we spent a couple hours debugging custom code which was working fine in Drupal 9 (!?) and blowing up because of this issue in Drupal 10.
The code in question was in a custom theme in a
hook_preprocess_menu()
:$route_name = \Drupal::getContainer()->get('path.matcher')->isFrontPage() ? '<front>' : '<current>'; $links = \Drupal::languageManager()->getLanguageSwitchLinks(LanguageInterface::TYPE_INTERFACE, Url::fromRoute($route_name));
And kind of contrary to getLanguageSwitchLinks() documentation, we were getting an object with an empty links array, leading subsequent code to blow up completely.
Againโ those exact same lines were working in Drupal 9, and not working, due precisely to the reasons discussed in this issue, in Drupal 10. So something has made this issue a higher priority somehow.
- ๐บ๐ธUnited States MegaKeegMan
Working with mlncn, our working code looks like:
// $url contains <current> - but we need real route for accessManager. $url = Url::fromRoute($route_name); // Create path and request. $path = $url->toString(); $request = Request::create($path); $urlFull = Url::createFromRequest($request); $links = \Drupal::languageManager()->getLanguageSwitchLinks(LanguageInterface::TYPE_INTERFACE, $urlFull);
To clarify, the old code worked up until 9.5.4, and broke in Drupal 10. The code here in this comment fixed the issue. Thanks for the example!
- ๐ฎ๐ณIndia sumit_saini
Facing a similar issue described in #13. Patch suggested in #11 fixes the issue for us.