Entities tokens might cause problems when field prefix is empty

Created on 15 December 2021, over 2 years ago
Updated 3 February 2023, over 1 year ago

Problem/Motivation

If we remove the "body" field from a node content type and add another text field called "summary" to that content type, the token [node:summary] is not working anymore when field prefix has been removed.

Steps to reproduce

  • Install and activate Token β†’ module
  • Alter field_ui.settings.yml, set field_prefix: '' and import the config
  • Manage the Page content type fields, remove the body field
  • Add a text field called "Summary" (with "summary" as machine name) to the Page content type fields
  • Create a page node and fill in your summary field
  • Use the token (ex: in a metatag content type description add [node:summary])
  • Check the use of your token, no data comes up (with the previous example: View your node and access the source code ; there is no meta description)

Proposed resolution

One of the solutions would be to rename the token, since [node:summary] token is related to the body field it should therefore be called [node:body_summary] or [node:body:summary].

As it might break things on a lot of websites using that token, and since this would only solve the problem for the [node:summary] token when it can also happens with any other node tokens, the other solution would be to forbid to give a machine name equal to a node token key (nid, vid, type, title, body, summary, langcode, url, created, changed, author) when we create fields with an empty field_prefix.

I am attributing this issue to the node system component because I met the problem with the nodes but we can have the same problem with any other entity (taxonomy term, user, etc.) so it's something which should be done for all entities tokens.
And it's not related to the Token module, node.tokens.inc, taxonomy.tokens.inc, user.tokens.inc are stored in the core files so it should be fixed directly in core (+ Token module could be enabled after the fields have been created so it doesn't make sense to fix this in the Token module).

πŸ› Bug report
Status

Needs work

Version

9.5

Component
Node systemΒ  β†’

Last updated less than a minute ago

No maintainer
Created by

πŸ‡«πŸ‡·France MacSim

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

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.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Can the MR be updated for 10.1 please

    Also left a few comments on the existing MR.

    Will need a change record to announce the new parameter.

    Thanks

  • First commit to issue fork.
Production build 0.71.5 2024