An option to enable tokens support

Created on 19 August 2024, 10 months ago
Updated 4 September 2024, 9 months ago

Problem/Motivation

I'm using ECA module to create a custom ECA block. While building the block, I need to apply some stylings, and I'm using Tailwind for theme development. Tailwind allows us to use classes with square brackets, for example https://tailwindcss.com/docs/hover-focus-and-other-states#arbitrary-groups

Steps to reproduce

  1. Create a custom ECA block by using ECA block event.
  2. Add action Renderer: Add Class, and configure this action to use a class name with square brackets (for example: [&_.cf-form-label]:tw-hidden - this class is to set hidden for all children having the class .cf-form-label).
  3. Everything in the square brackets is removed since ECA captured it as a token, and this token does not exist, so an empty string is returned

Proposed resolution

With all fields supporting tokens, it would be great if there is an option to enable token support or not.

πŸ’¬ Support request
Status

Fixed

Version

2.0

Component

Documentation

Created by

πŸ‡ΊπŸ‡ΈUnited States sea2709 Texas

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

Comments & Activities

  • Issue created by @sea2709
  • πŸ‡ΊπŸ‡ΈUnited States sea2709 Texas

    I also noticed that in the action Render: Add Class, the machine name field is a token support field as well. I would like to set the machine name as "wrapper][form][submit", and the name ends up with wrapper][submit. I'm not sure if it makes sense that machine name doesn't support token, or there should be an option to enable token support or not!

  • πŸ‡ΊπŸ‡ΈUnited States sea2709 Texas

    When I dug into the code, I noticed in the Actions.php (service class for Drupal core actions in ECA), it adds to the action plugin configuration an option "replace_tokens". I'm curious, how this setting is being used and can we expand this option to other plugin actions?

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    I remember a recent discussion on Slack with the same topic. As changing the token replacement behaviour at this point because that would break a lot of existing ECA models, it is better to define 2 tokens named [bracket:open] and [bracket:close] with the values [ and ]. Then use those tokens instead of the brackets at all places where you want to avoid replacements. Those tokens will then be replaced with the brackets, and as token replacement is not recursive by default, you should end up with the required result.

    Extra tip: with the ECA token generate event event, you can define those tokens globally so that you don't have to do that everywhere across all your models.

  • Status changed to Closed: works as designed 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States sea2709 Texas

    Thanks @jurgenhaas for your tip. Yeah, I didn't think about a token with bracket as value.

  • Status changed to Fixed 10 months ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    I'm adding a sample for that in the ECA Guide, I think. Added an issue at https://gitlab.lakedrops.com/drupal/documentation/eca/-/issues/69

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024