Entities tokens might cause problems when field prefix is empty

Created on 15 December 2021, over 3 years ago
Updated 3 February 2023, about 2 years 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 about 11 hours 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

Merge Requests

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.
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Added some minor comments on the MR, but this needs a full reroll on 11.x. Neither rebasing or merging locally worked well.

    Also, I'm not sure that just checking for an empty field prefix is enough here. I know this is pedantic but what if someone had a field prefix of "sum" and then made an "mary" field, that'd result in the same bug.

    Finally, the error message "The machine-readable name is already in use" is not accurate as the conflict is actually in the token system, not a field's machine name.

    Also swapping the component here as this is not node specific.

  • Pipeline finished with Failed
    9 days ago
    Total: 120s
    #458400
  • Pipeline finished with Canceled
    9 days ago
    Total: 250s
    #458403
  • Pipeline finished with Failed
    9 days ago
    Total: 423s
    #458405
  • Pipeline finished with Failed
    9 days ago
    Total: 532s
    #458409
  • Pipeline finished with Failed
    9 days ago
    Total: 521s
    #458578
  • Pipeline finished with Failed
    9 days ago
    Total: 553s
    #458611
  • Pipeline finished with Failed
    9 days ago
    Total: 553s
    #458662
  • Pipeline finished with Failed
    8 days ago
    Total: 377s
    #458926
  • Pipeline finished with Failed
    7 days ago
    Total: 502s
    #459949
  • πŸ‡«πŸ‡·France MacSim

    Updated MR to reflect what #14 said.
    But since token service is not part of drupal core, tests can't succeed.
    This could potentially move to Token issues. Anyway nothing would happen without the module being enabled.

Production build 0.71.5 2024