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