Entity specific token support

Created on 24 October 2023, about 1 year ago
Updated 2 February 2024, 10 months ago

Problem/Motivation

Right now only global tokens are available. I think it would be a great addition to have all field and entity-related data available as tokens.

That way you can write prompts like this, where a body field serves as the context:

Write an SEO description based on the context, and make sure to include the name of the product [node:field_product_ref:entity:title].

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

🇹🇭Thailand AlfTheCat

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @AlfTheCat
  • 🇩🇪Germany marcus_johansson

    So I can replicate this, is it an entity references fields entity that does not show up or how would I replicate this.

    Currently I do see the author of a node for instance when using tokens.

  • Assigned to marcus_johansson
  • 🇹🇷Turkey orkut murat yılmaz Istanbul

    It could be nice to add Entity API → as a dependency. Also, there is a great feature ✨ Consistent tokens support across all entities and fields Needs work , which will be added to token → module soon.

  • 🇩🇪Germany marcus_johansson

    Thanks for reporting the missing feature, but I am still not able to understand what is missing :)

    Do you actually even need Entity API for Tokens to work in D8+? The added feature for Token will be great for sure.

    Currently I have tested entity references and other fields and it seems to work. To be able to use the Tokens in the AI Interpolator you need to:

    1. Download and Install the Token module
    2. Under certain fields like OpenAI Text to Text for instance, you can choose Advanced Mode and use Tokens to prompt.
    3. Note - Advanced mode is not available on all rules

    Is there some place where this fails or where I misunderstood what is missing?

    If you mean something like Advanced Entity Tokens → that should also work already with that module, but I'm working on an interpolator plugin to make this easier with dynamic entity injection from autocomplete fields.

    What is also missing currently for the Token module is some way to do iteration. I'm trying to figure out that at the moment. So if you use the SERP module for instance and generate 10 links from a search word and you want to run a complex prompt on each of those separately, its not possible at the moment.

  • 🇹🇭Thailand AlfTheCat

    Hi Marcus, I'm experiencing this on taxonomy terms. I haven't checked nodes, I didn't think to check token support there.

    The example was just a general example. My specific case relates to taxonomy terms and I'm on Drupal 10.1.5.

  • 🇹🇷Turkey orkut murat yılmaz Istanbul

    @Marcus, for using more tokens from different entities, it would be nice to have Entity API installed. As said on the module description:

    It ships with the Entity tokens module which makes sure there are tokens for most entity properties and fields, i.e. it provides token replacements for all entity properties (or fields) that have no tokens and are known to the entity module (read about the entity property info API below).

    • b2fdc88f committed on main
      Issue #3396303: Entity specific token support
      
  • 🇩🇪Germany marcus_johansson

    @AlfTheCat - Thank you, I could replicate this. I have pushed a change that would fix this to main branch and it will be in alpha4.

    For some reason the keys uses to load the Token trees do not match the entity type data names, for taxonomy_term (its term).

    I have also tested blocks, contacts, nodes and a custom entity.

  • 🇩🇪Germany marcus_johansson

    @Orkut Murat Yılmaz - Thank you for clarification, but I can only see that module available in Drupal 7 version of Entity API. As far as I could see this is built into Token module in Drupal 8+. Could you verify that its the same, so I am not missing something?

  • 🇹🇷Turkey orkut murat yılmaz Istanbul

    @Marcus, I've uninstalled Entity API and re-installed it again, the tokens are not effected. Sorry for misleading:)

  • 🇹🇭Thailand AlfTheCat

    Hi Marcus, awesome! I'll be back to work in a few hours and can't wait to jump in again.

  • Status changed to Needs review about 1 year ago
  • 🇹🇭Thailand AlfTheCat

    Tokens are working well now for taxonomy terms. Thanks for the fix!

  • Status changed to Fixed 10 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024