Multiple languages with Language from the URL (domain) results in wrong breadcrumb in JSON

Created on 3 September 2024, 4 months ago
Updated 5 September 2024, 4 months ago

When translating content and using URL (domain) as language detection, all URL objects return an absolute URL when converted to string. This causes the function setRouteContextFromRouteMatch and getRequestForPath to work with an URL including protocol and domain, which it seems not to be ment to do.

This breaks the breadcrumbs for all pages that have parents. At least when using this module to create a breadcrumb through a separate request, for example when doing do for JSON.

Tested this on a fresh install of Drupal 9.5.11 using the default profile and the following modules:
Computed Breadcrumbs
Content Translation
JSON:API
Language
Node
Path

1. Create a page. Lets put the path as "/news"
2. Create an article. Lets put the path as "/news/my-test-news-item"
3. Set language detection as URL > path prefix
4. Visit the JSON for the created article and see the correct breadcrumb in three pieces (protocol://domain/jsonapi/node/article/uuid)
5. Set language detection as URL > domain
6. Visit the JSON for the created article and see the breadcrumb in TWO pieces without the middle "news" part (protocol://domain/jsonapi/node/article/uuid)

I temporarily "fixed" this problem by shopin' of the URL with parse_url(), cleaning of the protocol/domain, to make it work in the env I'm working with since I couldn't figure out what setRouteContextFromRouteMatch and getRequestForPath are actually supposed to be doing.

πŸ› Bug report
Status

Postponed: needs info

Version

2.0

Component

Code

Created by

πŸ‡ΈπŸ‡ͺSweden agogo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @agogo
  • πŸ‡©πŸ‡ͺGermany spuky

    Drupal 9 has been deprecated for since 1. November 2023 can you check if it is the case in 10.3 or 11 ?

  • Status changed to Postponed: needs info 4 months ago
  • leymannx Berlin

    What does this "Visit JSON" part mean? Is this JSON:API? πŸ€”

  • leymannx Berlin

    (Postponed because we need to have this checked with D10/11.)

  • πŸ‡ΈπŸ‡ͺSweden agogo

    Tested again, exact same approach but with Drupal 10.3.2. Same problem. Cannot test Drupal 11 atm because of the DB version requirements.

    "Visit JSON" means checking the JSON output which are at the default location and can be viewed through a web browser (easiest way if you're not used to working with JSON). Just replace everything in brackets [protocol]://[domain]/jsonapi/node/article/[uuid] (for example http://local.drupal10/jsonapi/node/article/68a87a7a-e28b-492b-a83c-c734f...)

  • πŸ‡ΈπŸ‡ͺSweden agogo

    To clarify the issue:

    Normally when using URL objects one can decide wether the URL as a string (toString()) should be absolute or not with the function setAbsolute(). The default seems to be FALSE.

    When using multiple languages and language detection is set to domain, the setAbsolute() function makes no difference. The toString() function always returns the URL as an absolute domain.

    In function setRouteContextFromRouteMatch, the URL object created usually outputs the URL without protocol and domain when converted to string ($url->toString()). In this case "/news/my-test-news-item". This is sent to getRequestForPath().

    However, when using multiple languages and detection is set to domain, the string sent to getRequestForPath() is absolute. This seems to be where the module breaks down and results in a faulty breadcrumb.

Production build 0.71.5 2024