Tập tành print node ID value after submit a Webform attached to that node
29th May 2022Get the node ID value after submit a Webform attached to that node Drupal 9
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); }
Add new comment