0

I am new to Drupal. I want to create a Webform node when adding a webform. I used the code snippet in https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-automatically-create-a-webform-node-when-adding-a in my .module file. After I submitted a submission, it looks like this hook code snippet didn’t execute, the Webform node didn’t be created. Any thing wrong? What’s the right way to do this?

Here is the code in my mytrymodule.module file:

/**
 * Implements hook_webform_insert().
 */
function mytrymodule_webform_insert(\Drupal\webform\WebformInterface $webform)
{

  $node = \Drupal\node\entity\Node::create([
    'type' => 'webform',
    'title' => $webform->label(),
    'webform' => ['target_id' => $webform->id()],
  ]);
  $node->save();

}
  • How can we know what's wrong with your custom code when you don't show us your custom code and how you implemented it exactly? – leymannx Jun 17 at 18:55
  • Here is the code in my mytrymodule.module file: /** * Implements hook_webform_insert(). */ function mytrymodule_webform_insert(\Drupal\webform\WebformInterface $webform) { $node = \Drupal\node\entity\Node::create([ 'type' => 'webform', 'title' => $webform->label(), 'webform' => ['target_id' => $webform->id()], ]); $node->save(); } – Joseph Jun 17 at 19:12
  • Is your custom module enabled? – sonfd Jun 17 at 23:22
  • Did you create a webform node type? Or is it provided from a webform submodule? – leymannx Jun 18 at 5:12
  • I created a webform which has 6 elements on it. What I want to do is after I submit the webform, a node of this webform submission will be created automatically. I found the code snippet at drupal.org/docs/8/modules/webform/webform-cookbook/…, and used it in my “.module” file. All other functions/hooks in my “.module” file work fine. However, it looks like this copied code snippet doesn't work, during my debugging, the system didn’t stop at the breakpoint in this hook. I am new to drupal. Please help! – Joseph Jun 19 at 3:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.