Get the node ID value after submit a Webform attached to that node
Example how to Get the node ID value after submit a Webform attached to that node.
if ($source_entity = $webform_submission->getSourceEntity()) {
$nid = $source_entity->id();
}
else {
$nid = NULL;
}
Example 2:
function MODULE_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { if ($form_id == 'webform_submission_product_add_form') { $form['actions']['submit']['#submit'][] = 'custom_submit_handler'; } } function custom_submit_handler(&$form, \Drupal\Core\Form\FormStateInterface $form_state) { /** @var \Drupal\webform\WebformSubmissionForm $form_object */ $form_object = $form_state->getFormObject(); /** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */ $webform_submission = $form_object->getEntity(); $source = $webform_submission->getSourceEntity(); $nid = $source->id(); kint($nid); }