how to set value of a list text field

Created on 19 February 2025, 11 days ago

Probably a simple question - but I can't find the answer anywhere - sorry:

I have an entity with a list text field with several options/values ​​entered, in the form of hours and minutes (06:00, 06:30, 07:00 etc. until 22:30).
The entity also has a date field that always contains exactly one value for each node (with Date + Time).
My intention is to transfer the value of the hours and minutes from the date field to the list field when the entity is created or updated.

What I have tried so far:

Event:
- presave content entity (not yet "Insert content entity" because it should first work with existing nodes)
- update content entity

Action:
- set field value

I can display (via "display a message") the correct value with several tokens (e.g. [eventinstance:date:custom:H:i]), but with setting the value in the list field I haven't even managed to set a fixed value (e.g. 12:30) (instead of a token).

So my question is: how do I set the value (only one, not multiple) of a list text field?

Many thanks!

Wiegand

💬 Support request
Status

Active

Version

2.1

Component

Documentation

Created by

🇩🇪Germany 4kant

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

Comments & Activities

  • Issue created by @4kant
  • 🇩🇪Germany 4kant

    I answer my question myself:

    I found out that it works with the machine_name of the field value to be inserted .

    Example: when I created the field, one field value I entered was "12:30" (all values have a colon as described above)
    But the machine_name generated by Drupal is "12_30" (all colons had been replaced by an underscore ...no surprise)

    So I need to change the token from
    [eventinstance:date:custom:H:i]) to [eventinstance:date:custom:H_i])

    Don´t know whether this helps someone, but I hope I will find this issue next time ;-)

  • 🇩🇪Germany jurgenhaas Gottmadingen

    This is great, thanks for reporting and then even solving the issue. Thank you @4kant.

  • 🇩🇪Germany jurgenhaas Gottmadingen
Production build 0.71.5 2024