Action to alter webform element

Created on 7 June 2025, about 8 hours ago

Problem/Motivation

ECA webform already exposes the alter element event in ECA, but as far as I know, it is not yet possible to set the element properties through any ECA action since the respective tokens are read-only.

My use case is to dynamically update the cardinality of a webform element based on a field value in the webform submission's source entity.
Without using ECA, doing so involves:

  1. Implementing hook_webform_element_alter()
  2. Checking if the element is a multi-value input field by checking the value of $element['#multiple']
  3. Loading source entity through $form_state->getFormObject()->getSourceEntity()
  4. Load field value of source entity
  5. Setting the value of $element['#min_value'] to the field value
  6. Set $element['#add'], $element['#remove'], and $element['#add_more'] to FALSE

Currently, step 1 is already implemented in ECA webform, step 4 is possible through ECA content. Step 2 may be possible as well by just using ECA base and checking token values. Steps 3, 5, and 6 are not possible to perform.

Steps to reproduce

Proposed resolution

  • Add a new action to load source entity OR add source entity to event tokens
  • Add an action to use YAML key-value pairs to set $element properties.

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

2.1

Component

Code

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

Comments & Activities

Production build 0.71.5 2024