n Get the node ID value after submit a Webform attached to that node | CodimTh

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

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook