-2

Is there a working example of programmatically creating a webform?

I just need to see what works. The smallest excerpt will be helping out a lot. I can build on a foundation.

1

1 Answer 1

3

When you look around how to programmatically create a node you will finde patterns like this:

$node = Node::create([
  'type'        => 'article',
  'title'       => 'Druplicon test',
  'field_image' => [
    'target_id' => $file->id(),
    'alt' => 'Hello world',
    'title' => 'Goodbye world'
  ],
]);
$node->save();

Maybe that's similar for webforms or webform submissions? Okay, let's scan Webform's codebase for the following patterns: Webform::create and WebformSubmission::create. Wow! Lots of samples just in the module's code! Let's take these two as a start:

Note that you also automatically can create webforms (not webform submissions, but webforms) by exporting config on one environment and importing it on different environments.

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