Token name in RenderElementActionBase cannot be specified as nested token

Created on 11 April 2025, about 1 month ago

Problem/Motivation

The base class RenderElementActionBase includes the option to specify a token name:
https://git.drupalcode.org/project/eca/-/blob/2.1.x/modules/render/src/P...

However that is defined as type machine name. But a machine name doesn't allow ":" characters and that's why it's currently not possible to specify a nested token like "mytoken:nested".

Steps to reproduce

Proposed resolution

Change the configuration field type from machine name to a regular textfield type.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇩🇪Germany mxh Offenburg

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

Merge Requests

Comments & Activities

  • Issue created by @mxh
  • 🇩🇪Germany mxh Offenburg

    Basically this part needs to be changed from

    $form['token_name'] = [
          '#type' => 'machine_name',
          '#machine_name' => [
            'exists' => [$this, 'alwaysFalse'],
          ],
          '#title' => $this->t('Token name'),
          '#description' => $this->t('Optionally define a token name of this render element. It will be made available under that token name for later usage.'),
          '#default_value' => $this->configuration['token_name'],
          '#required' => FALSE,
          '#weight' => -28,
          '#eca_token_reference' => TRUE,
        ];
    

    into

    $form['token_name'] = [
          '#type' => 'textfield',
          '#maxlength' => 1024,
          '#title' => $this->t('Token name'),
          '#description' => $this->t('Optionally define a token name of this render element. It will be made available under that token name for later usage.'),
          '#default_value' => $this->configuration['token_name'],
          '#required' => FALSE,
          '#weight' => -28,
          '#eca_token_reference' => TRUE,
        ];
    
  • First commit to issue fork.
  • Merge request !499#3518824: replace machine_name to textfield → (Merged) created by julio_retkwa
  • Pipeline finished with Success
    23 days ago
    Total: 1329s
    #477482
  • 🇧🇷Brazil julio_retkwa Balneário Camboriú

    Hi @mxh I've added your suggestion to MR

    Thank you!

  • 🇧🇷Brazil julio_retkwa Balneário Camboriú
  • 🇧🇷Brazil julio_retkwa Balneário Camboriú
  • 🇩🇪Germany jurgenhaas Gottmadingen

    This is looking good, thanks @julio_retkwa for your contribution.

    We should add a follow-up issue to address the following related tasks:

    • There are 11 other cases where the field type machine_name is being used, most of them allow tokens as well and could run into the same problem. We should replace them all for consistency.
    • Most of those cases support tokens or require a token reference, both of which not being declared in the form field configuration. That should be added.
    • Form field validation: those fields that get the token reference attribute will still be validated. But others won't. We may consider our own validation as a replacement for the machine name validation that we've then lost.
  • 🇩🇪Germany jurgenhaas Gottmadingen
  • Pipeline finished with Skipped
    8 days ago
    #489092
  • Pipeline finished with Skipped
    8 days ago
    #489093
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Created follow-up issue 🐛 Avoid config form field type "machine_name" Active

    Merged this into 2.1.x and will now port this back and also into 3.0.x

  • Pipeline finished with Success
    8 days ago
    Total: 527s
    #489094
    • jurgenhaas committed a8dd6e86 on 2.0.x
      #3518824: replace machine_name to textfield
      
      
      (cherry picked from commit...
    • jurgenhaas committed f9cf5c10 on 1.1.x
      #3518824: replace machine_name to textfield
      
      
      (cherry picked from commit...
Production build 0.71.5 2024