0

I would like to add comments to the Sourcecode of my webforms in YAML.

# comment (without quotes).

But when I save this, it automatically gets removed.

20_e_mailadres:
  '#type': email
  '#title': E-mailadres
# write a comment here
21_werkmail:
  '#type': email
  '#title': werk E-mailadres

How do I add comments to a YAML webform so they are kept when I save?

  • 3
    Is this a feature request? Then it should be posted to the mentioned module's issue queue on drupal.org, not here on Drupal Answers. – leymannx Aug 14 at 6:24
  • I believe it's a "how to"? I can't imagine this isn't possible. To make the YAML-code more readable, it should be possible no? – KoenC Aug 14 at 7:07
  • You tell us what it is, but currently there is no question, just stating facts. Maybe update your question for clarification and also include what you've tried so far. When it's about YAML for reading data I think that would be no problem. But this YAML is also used to store data and then I guess it's a bit difficult to write a submit handler intelligent enough to distinguish between comments belonging to an element that got removed maybe or a new element that's been added maybe. So the program needs to read and handle the data before storing the updates. Difficult. – leymannx Aug 14 at 8:56
  • 2
    You also shouldn't prefix your elements with numbers, always start with letters instead. I'm currently working on a project where this has been done and now I can't access these element's information in Twig because variables must not start with numbers. – leymannx Aug 14 at 9:10
  • 1
    Afaik comments are removed from any config yml on import and export. This is true for any config. I've used a workaround with migrations where I save a copy of the yml with my comments in a separate folder (custom module) so they can be referenced later. The problem is the developer has to make sure to update them whenever they update the yml. – sonfd Aug 24 at 11:38
3

Context

  • Drupal 8.x
  • Webform module
  • YAML comments

Use-case

  • developer KoenC wishes to add comments to a YAML file and have those comments retained upon save

Problem

  • Per the YAML specification, comments are specified as "throwaway" artifacts.
  • This means that YAML commments are not required to be preserved by parsers that implement the YAML specification

Workaround

| improve this answer | |
2

Comments are not supported in the YAML source because the YAML is decoded and reencoded every time an element is updated.

On my todo list is to add support for '#admin_notes' to each element which could be used to store 'comments'. For now, you could add a '#comment' property to any element.

@see Issue #3165328: Add support for #admin_notes to webform elements

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.