Add "Use token" option to drop-down lists

Created on 21 February 2024, 10 months ago
Updated 30 May 2024, 7 months ago

Problem/Motivation

In most cases, where a config form field of an action or condition plugin has a drop-down (select list), it would be nice to support tokens. Something similar has already been discussed in Allow tokens in "Entity: create new" for langcode Needs work .

Proposed resolution

Let's add a new option Use token to all (or most) select fields and provide a pre-defined token name that needed to be pre-filled with the value when using that option.

Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

🇩🇪Germany jurgenhaas Gottmadingen

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

Comments & Activities

  • Issue created by @jurgenhaas
  • 🇩🇪Germany jurgenhaas Gottmadingen

    This has also been discussed at https://drupal.slack.com/archives/C0287U62CSG/p1708437647447219:

    
    James Shields
      23 hours ago
    Something that would be really amazing would be the ability to build configurable components in ECA, and then be able to use them in further ECA models. For example, I'm working on a number of models that email different groups of users. It would be amazing if I could build a component in ECA that called a view, and emailed the users selected. It would need to allow tokens to be passed in for the view, or possibly the contextual filter, and the message contents, but once built that could be used across multiple models.
    
    
    
    
    4 replies
    
    
    jurgenhaas
      23 hours ago
    Yep, we've done that. Not for emails, but for log message handling. The idea is still the same, though.
    You can build your generic "Send email model" that contains a custom event.
    All your other models trigger that custom event with all the necessary arguments (=tokens), and then your generic model does all the magic about sending emails.
    
    
    James Shields
      23 hours ago
    Oh, that could work. I'm already triggering a custom event to send my emails. It didn't occur to me that the custom event handler doesn't have to be in the same model.
    
    
    James Shields
      23 hours ago
    Can you use a token to select the name of the view a model calls?
    
    
    jurgenhaas
      23 hours ago
    Aah, that's a good point. No, we currently can't since that config field is a select field (drop-down). But we're currently working on an issue where the language selector could do with token support as well and we're doing it there with a select list option called "Use token", and then the plugin uses a pre-defined token name for that. We should probably add something similar to all config fields that come with drop-downs.
  • 🇮🇪Ireland lostcarpark

    This sounds like an awesome feature!

  • 🇩🇪Germany jurgenhaas Gottmadingen
    • jurgenhaas committed 0bfbb9db on 2.0.x
      Issue #3422936 by jurgenhaas, lostcarpark: Add "Use token" option to...
  • 🇩🇪Germany jurgenhaas Gottmadingen

    We've now implemented a generic method to support tokens in drop down fields over at Allow tokens in "Entity: create new" for langcode Needs work with language codes.

    This is now adopted to the views query action plugin as well and can be tested in the 2.0.x-dev release.

  • 🇩🇪Germany jurgenhaas Gottmadingen

    There are 36 plugins altogether that we can improve with this new feature:

    web/modules/contrib/eca/modules/access/src/Plugin/Action
    - SetAccessResult.php
    web/modules/contrib/eca/modules/base/src/Plugin/Action
    - SetEcaLogLevel.php
    - Translate.php
    web/modules/contrib/eca/modules/base/src/Plugin/ECA/Condition
    - ListContains.php
    web/modules/contrib/eca/modules/cache/src/Plugin/Action
    - CacheActionBase.php
    web/modules/contrib/eca/modules/content/src/Plugin/Action
    - FieldUpdateActionBase.php
    - NewEntity.php
    web/modules/contrib/eca/modules/content/src/Plugin/ECA/Condition
    - EntityFieldIsAccessible.php
    - EntityIsAccessible.php
    - EntityTypeAndBundle.php
    web/modules/contrib/eca/modules/content/src/Service
    - EntityLoader.php
    web/modules/contrib/eca/modules/endpoint/src/Plugin/Action
    - SetAjaxResponseMessageCommand.php
    - SetAjaxResponseOpenOffCanvasDialogCommand.php
    web/modules/contrib/eca/modules/file/src/Plugin/Action
    - FileRename.php
    web/modules/contrib/eca/modules/form/src/Plugin/Action
    - FormAddFieldActionBase.php
    - FormAddSubmitButton.php
    - FormSetMethod.php
    web/modules/contrib/eca/modules/log/src/Plugin/Action
    - LogMessage.php
    web/modules/contrib/eca/modules/miscellaneous/src/Plugin
    - RouteTrait.php
    web/modules/contrib/eca/modules/queue/src/Plugin/Action
    - EnqueueTaskDelayed.php
    web/modules/contrib/eca/modules/render/src/Plugin/Action
    - Cacheability.php
    - GetFileContents.php
    - Link.php
    - RenderElementActionBase.php
    - Serialize.php
    - Text.php
    - Unserialize.php
    - Views.php
    web/modules/contrib/eca/modules/ui/src/Form
    - Settings.php
    web/modules/contrib/eca/modules/user/src/Plugin/ECA/Condition
    - CurrentUserPermission.php
    - CurrentUserRole.php
    web/modules/contrib/eca/modules/views/src/Plugin/Action
    - ViewsQuery.php
    web/modules/contrib/eca/modules/workflow/src/Plugin/Action
    - WorkflowTransition.php
    web/modules/contrib/eca/src/Plugin/Action
    - ListAddBase.php
    - ListRemoveBase.php
    web/modules/contrib/eca/src/Plugin/ECA/Condition
    - StringComparisonBase.php
    
    • jurgenhaas committed fbb430b3 on 2.0.x
      Issue #3422936 by jurgenhaas, lostcarpark: Add "Use token" option to...
    • jurgenhaas committed 887f5422 on 2.0.x
      Issue #3422936 by jurgenhaas, lostcarpark: Add "Use token" option to...
  • Status changed to Fixed 7 months ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    All drop-down config fields in ECA now support tokens. See also the CR at https://www.drupal.org/node/3447358 which is relevant for module maintainers who probably want to update their plugins accordingly.

  • 🇮🇪Ireland lostcarpark

    Brilliant! I will have to try out the 2.x branch soon.

    Thanks for this feature.

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

Production build 0.71.5 2024