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
- Enable token module
- Enable link module
- Create content type
- Add link field to content type form display. Allow unlimited values so we can test lots of things.
- Go to /node/add/ to create a new piece of content and to test tokens in the url input of a link field.
- Enter title
- Enter link title in your newly created link field
-
Enter url with a token in it.
http://twitter.com/share?url=[current-page:url:absolute]&text=[current-page:title]
/node/[node:id]
- 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