Implement Token Replacements

Created on 28 July 2023, 11 months ago
Updated 18 May 2024, 29 days ago

Problem/Motivation

Token replacements can be used within the Field Display UI, but are never replace when slots or props are rendered.

πŸ“Œ Task
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States droath

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

Merge Requests

Comments & Activities

  • Issue created by @droath
  • Status changed to Needs review 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States droath

    I've added token support for props/slots in the module. Let me know if there is anything else that should be accounted for.

  • Status changed to Needs work 11 months ago
  • First commit to issue fork.
  • Pipeline finished with Success
    7 months ago
    Total: 293s
    #55740
  • πŸ‡ΊπŸ‡ΈUnited States jayhuskins

    On the static mapping form, the "Browse available tokens" helper does not include tokens for the entity being displayed. Is this intentional? If I used a token for a static mapping like [node:title] for a node display, would the token be evaluated for each node individually?

  • First commit to issue fork.
  • Pipeline finished with Success
    5 months ago
    Total: 149s
    #74061
  • Status changed to Needs review 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    Added the current entity type to the token browser, and expanded the token replacement to cover view modes -- previously it only applied on field formatters.

  • Status changed to Needs work 5 months ago
  • e0ipso Can Picafort

    I see the suggestions on the MR have not been addressed or contested yet. Setting back to Needs Work.

  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    I don't understand at this point what the data types for each SDC parameter types are allowed to be -- I patched this as an experiment to see if I could get it to work -- and it does work fine for strings.

    I've had a tough time finding any documentation for the SDC interface -- but got errors when declaring a prop as a number so I just changed everything to be a string (aside from the slots).

    I've gone through the documentation in this section: https://www.drupal.org/docs/develop/theming-drupal/using-single-director... β†’ ... but there's nothing there describing how to use the various prop types, or examples of how to use these effectively...

    Is there a good resource describing these types?

    `drush generate sdc` prompts for properties and lets you pick among these types:

    1. String
    2. Number
    3. Boolean
    4. Array
    5. Object
    6. Always Null

    ... I'm thinking if we can detect the prop type here, we can then do some casting (for numeric types) or wrapping (e.g. for array, if the resolved token is a string)

    (not sure why there would be an "Always Null" prop -- should this ignore anything assigned, or throw an exception?)

  • Pipeline finished with Failed
    5 months ago
    Total: 154s
    #84481
  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    Took the code from @e0ipso's link, for recursive token replacement.

    I have this working with fixed_value props -- I did have an issue destructuring the output of the token replacement where my scenario used it, so I think there might be another spot or two where this needs to get fixed as well (the token replacement was wrapped with an extra array).

    Still in progress, but partially working...

  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    Linking to related core issue, maybe there's some hints in there, or something helpful here.

    Using the patch, I was able to pass the node url as a prop with a token.

  • e0ipso Can Picafort

    @freelock any chance you could take this through the finish line?

  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    We work together, I was hoping to keep going on it with him. We're under a heavy workload atm, but next time I have to implement a component I'll look into it.

  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    The patch is currently working for many tokens, but I have one scenario we need still broken -- trying to get a particular date format on a Smart Date. Haven't had a chance to circle back to fix that.

    Otherwise I think it still needs help for non-string props -- I'm wondering if we should attempt to automatically cast whatever is in Fixed Values to a numeric or boolean type? This might be a different issue...

    Cheers,
    John

  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    It would be useful to have the tokens in twig, like in views, so we could modify the output further.

  • e0ipso Can Picafort

    I did another review path. I feel this is getting closer and closer, but not there yet.

  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    My comment in #15 turned out to actually be a bug in Smart Date module, which is fixed in their version 4.1.0.

  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    I started looking into the failing test. Still not sure why it's failing exactly, but will need to check the logic for how it's processing tokens. I think it was choking on an array value in the test.

  • e0ipso Can Picafort

    Thanks @mortona2k and @freelock! Please, ping me in Slack when you want my attention back to this issue.

Production build 0.69.0 2024