I'm currently developing a Webform based module (D9). One functionality I'm working on is around form "interdependency" : for a given form, some fields can be pre-filled from another webform submission of the same user. The hard part is tat I want to prevent end-user editing the prefilled data; I'm think about / testing multiples options :
- Simply add
#disabled
property to each prefilled fields : not good because disabled
field values are NOT submitted
- Simply add
#readonly
property to each prefilled fields : not good because some field cannot be "readonly" such as select (and readonly
attribute can be easily removed by end-user)
- Do not "write protect" pre-filled fields, but override all prefilled fields juste before entity saving (entity presave maybe ?) with initial data values
- Alter each-prefilled field to transform them to textfield, or markup + hidden field
For about all those options I need to be able to alter the custom composite fields, and theirs values (multivalues custom composite field). For now, I'm able to loop over the custom composite structure ($form['elements']['my_composite_field']['#element']['my_composite_subfield']
) in classic hook_form_alter
; but I don't know how to alter my_composite_subfield
fields individually (because pre-filled fields must be altered, unlike any new item added by user (native "add more item" ajax button).
Can you please help ? Which hook can be used ? Or maybe a Webform custom handler ?
Thanks