Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

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);
}

Comments

Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon