1

I am building a D8 module that, for configuration, needs a list of webforms and their fields (just the entity reference fields, but I am not picky)

I can get the webforms with this:

  $webforms = \Drupal::entityTypeManager()->getStorage('webform')->loadMultiple(null);

But once I get the returned elements (Drupal\webform\Entity\Webform::__set_state), how can I fetch the elements in the webform referenced?

  • Are you trying to get the values a user entered? or just the field names the form contains? – No Sssweat Apr 20 at 12:20
  • Thanks, I was looking for the form's field names, and found the result myself.... eventually. Posted below. – Michael D. Moradzadeh Apr 21 at 16:52
2

By trawling through the code, I found this handy function in the Entity code, and it works perfectly:

 $elements = $webform->getElementsDecodedAndFlattened();

This gives a nice array of the elements in the webform itself.

If you want the results of a submission, grab that entity and use:

$data = $entity->getData();

I hope this helps

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.