Quantcast
Viewing all articles
Browse latest Browse all 295232

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

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

Reference: https://www.drupal.org/core/beta-changes
Issue categoryBug because what should be routable, and language prefixed, isn't.
Prioritized changesBugfixes are considered prioritized changes.
DisruptionNo disruption, improved user experience for those running multilingual sites.

Viewing all articles
Browse latest Browse all 295232

Trending Articles