Allow tokens for url of the Link field

Created on 19 August 2017, over 7 years ago
Updated 8 February 2024, 11 months ago

Problem/Motivation

The link text of the link field does allow to use tokens, but the url does not.

A use case example is using the link for a sharing function where the link is

http://twitter.com/share?url=[current-page:url:absolute]&text=[current-page:title]

and the link text "Twitter".

It does not appear logical why I can use tokens for the link text and not for the title. Therefore I marked this as a bug.

Steps to reproduce

  1. Enable token module
  2. Enable link module
  3. Create content type
  4. Add link field to content type form display. Allow unlimited values so we can test lots of things.
  5. Go to /node/add/ to create a new piece of content and to test tokens in the url input of a link field.
  6. Enter title
  7. Enter link title in your newly created link field
  8. Enter url with a token in it.
    • http://twitter.com/share?url=[current-page:url:absolute]&text=[current-page:title]
    • /node/[node:id]
  9. Save the content and see how this doesn't replace the token

Proposed resolution

Optionally allow tokens to be used in the url field of link fields

Remaining tasks

This currently only works on form submissions, tested with a migration and it seems more work is needed to make this work in a migration, my assumption is that it probably won't work in other non-form related entity creations either. example JSON API
links are rendered correctly on the front end, but they are not tied to the context in the database, and are instead tied to the node itself.
The contrib module: https://www.drupal.org/project/field_group_link does not render link properly which leads to other questions about how these types of links should be rendered.
Additionally, this does not account for entity references via token.

User interface changes

Maybe allow tokens on the link field creation form.

API changes

Add new method for generating links with tokens.
Add new scheme:// type for tokens token://

Data model changes

Adds token context array to url options array in database so that contextual tokens can validate on form submission.
a:1:{s:7:"context";a:1:{s:4:"node";s:3:"193";}}

Release notes snippet

Feature request
Status

Needs work

Version

11.0 🔥

Component
Link 

Last updated 6 days ago

Created by

🇩🇪Germany demonde

Live updates comments and jobs are added and updated live.
  • Needs subsystem maintainer review

    It is used to alert the maintainer(s) of a particular core subsystem that an issue significantly impacts their subsystem, and their signoff is needed (see the governance policy draft for more information). Also, if you use this tag, make sure the issue component is set to the correct subsystem. If an issue significantly impacts more than one subsystem, use needs framework manager review instead.

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.

Production build 0.71.5 2024