4

I would like to copy the Webform handler from 1 Webform into another. I can get hold of Webform settings via:

/** @var \Drupal\webform\WebformInterface $webform */
$webform = \Drupal::entityTypeManager()->getStorage('webform')->load('example_webform_id');
$webform->getSettings();
=> [
     "ajax" => false,
     "ajax_scroll_top" => "",
     "ajax_progress_type" => "",
     "ajax_effect" => "",
     ...

However that doesn't include the handler config that I would need and a way to save its new config as well.

I also tried it via the handler object itself:

/** @var \Drupal\webform\Plugin\WebformHandlerInterface[] $handlers */
$handlers = $webform->getHandlers('example_webform_handler_id');
$handler = $handlers->getIterator()->current();
$handler->setConfiguration($new_handler_config)->save();

for which it appears that there is no save() operation in the handler class:

Error: Call to undefined method ::save()

Any way I can do this programmatically that you may know of?

1 Answer 1

2

Ended up using the ConfigFactory service, which I believe is fine to do:

$config = \Drupal::configFactory()->getEditable('webform.webform.' . $webform->id());
$config_key = 'handlers.' . $webform_handler_id;
$config->set($config_key, $new_handler_config)->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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