Programmatic list of Webform elements? 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()-&gt;getStorage('webform')-&gt;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?
By trawling through the code, I found this handy function in the Entity code, and it works perfectly:

 $elements = $webform-&gt;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-&gt;getData();


I hope this helps