I'm just wondering how to add a new option to the webform submission formatters for a specific element? is it driven by the field API?
1 Answer
What you have in that list are date formats. You can manage those, including adding new ones, at /admin/config/regional/date-time.
-
The question is, how do I do that programmatically? I don't want it's just for the date field, how about for other types of fields– heshanlkCommented Aug 31, 2018 at 13:04
-
Each is different - have a look at the different classes in webform/src/Plugin/WebformElement/*.php to get an idea of where each element type gets its data from. There isn't a universal method, so you'll need to approach each differently. For your given example, look at
DateBase::getItemFormats()
, which usesDateFormat::loadMultiple()
directly, and doesn't ask the rest of the system for input. This makes sense, because when rendering that value, it needs to know that it has a valid date format that the system knows about. If you were able to add one that wasn't a valid date format...– Clive ♦Commented Aug 31, 2018 at 14:28 -
...it would break on render. So the values are gathered from an existing known API, and new values need to be added to that API's storage - Webform only has an outside view of them– Clive ♦Commented Aug 31, 2018 at 14:29