In your custom module add a folder src/Plugin/WebformHandler
and create a file Subscription.php
. Add the following code:
<?php
namespace Drupal\<mycustommodule>\Plugin\WebformHandler;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Plugin\WebformHandlerBase;
use Drupal\webform\webformSubmissionInterface;
/**
* Form submission handler.
*
* @WebformHandler(
* id = "subscription",
* label = @Translation("Subscription"),
* category = @Translation("Form Handler"),
* description = @Translation("Administers subscriptions via SOAP"),
* cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_SINGLE,
* results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
* )
*/
class Subscription extends WebformHandlerBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [];
}
const SOAP_URL = 'x'; // url of soap call here
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
// The data to send to the API
$values = $webform_submission->getData();
$email = strtolower($values['e_mail']);
$first_name = $values['first_name'];
$last_name = $values['last_name'];
// Add your SOAP Call here
$client = new SoapClient(self::SOAP_URL);
// .. Go on here
}
}
Enable the module and clear cache. Now, in your webform backend, go to settings and then emails / handlers (/admin/structure/webform/manage//handlers). Add your handler here. For a little more detail and instructions, see: https://stefvanlooveren.me/blog/how-create-mailchimp-subscription-drupal-8-webform-module