FieldPluginBase::renderAsLink() loses language prefix for tokenized paths

Created on 14 February 2015, almost 10 years ago
Updated 14 September 2024, 2 months ago

Problem/Motivation

  • Add a field to a View where you can type in a path and render it as a link, and then type in a path that includes token (e.g., {{nid}}). Or, import the views.view.test_dropbutton.yml View, which has that (the "Custom text" field).
  • Enable the Language module, add a language to the site, and then go to that View's page with a language prefix. E.g., if using the test_dropbutton View, go to http://example.com/en/test-dropbutton.
  • Notice that the link (e.g., the "Custom text" link) takes you to a URL that no longer has that language prefix.
  • The problem is that FieldPluginBase::renderAsLink() calls Url::fromUri('user-path:...') on the tokenized path, and while tokenized, that doesn't match a route, so falls back to 'base:', which does not apply language prefixing (since you don't want language prefixing for unrouted paths). Then tokens are replaced, but we're already in the base: scheme, so too late.

Proposed resolution

Run the path (technically a URI at the point in the code) through the path validator to convert to a routable Url() object.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Beta phase evaluation

<!--Uncomment the relevant rows for the issue. -->
πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 9 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States effulgentsia

Live updates comments and jobs are added and updated live.
  • VDC

    Related to the Views in Drupal Core initiative.

  • D8MI

    (Drupal 8 Multilingual Initiative) is the tag used by the multilingual initiative to mark core issues (and some contributed module issues). For versions other than Drupal 8, use the i18n (Internationalization) tag on issues which involve or affect multilingual / multinational support. That is preferred over Translation.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡ΏNew Zealand quietone

    There has been no activity here for 9 years.

    Can someone confirm that this is still a proeblem?

    If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024