Add a webform handler to the webform configuration and use the method submitForm() of the handler, which provides the submission entity as argument:
mymodule/src/Plugin/WebformHandler/MyWebformHandler.php:
<?php
namespace Drupal\mymodule\Plugin\WebformHandler;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Plugin\WebformHandlerBase;
use Drupal\webform\WebformSubmissionInterface;
/**
* My webform submission handler.
*
* @WebformHandler(
* id = "my_webform_handler",
* label = @Translation("My Webform Handler"),
* category = @Translation("Example"),
* description = @Translation("Example of a webform handler."),
* cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_SINGLE,
* results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
* submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_OPTIONAL,
* )
*/
class MyWebformHandler extends WebformHandlerBase {
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
$submission_id = $webform_submission->id();
// my submit logic
}
}