K
K
Kirill2018-02-23 14:42:23
Drupal
Kirill, 2018-02-23 14:42:23

Module for creating a node from Webform fields?

Hey! the task arose on Drupal8 software to create material from the fields filled in the form, I have not yet written modules but I want to learn) please tell me the beginning of the process.
I created a module, enabled it, added a hook in the name.module file

/**
 * Implements hook_webform_insert().
 */
function add_dive_webform_insert(\Drupal\webform\WebformInterface $webform) {
  $node = \Drupal\node\entity\Node::create([
    'type' => 'NAME-NODE',
    'title' => $webform->label(),
    'webform' => ['target_id' => $webform->id()],
  ]);
  $node->save();

  drupal_set_message(t('Node %label created.', ['%label' => $node->label()]));
}

and then plugging) what file should be created Schaub earned? searched already, there are no similar examples at all, please help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
afi13, 2018-02-24
@KirillSPB777

Good afternoon,
hook_entity_insert() is called when an entity is created, i.e. you create a node, taxonomy (or some other entity) in the admin panel, and after creation, this hook is called where only the created entity gets.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question