You are here

function webform_node_insert in Webform 6.3

Same name and namespace in other branches
  1. 7.4 webform.module \webform_node_insert()
  2. 7.3 webform.module \webform_node_insert()

Implements hook_node_insert().

3 calls to webform_node_insert()
webform_ensure_record in ./webform.module
Utility function to ensure that a webform record exists in the database.
webform_nodeapi in ./webform.module
Implements hook_nodeapi().
webform_node_update in ./webform.module
Implements hook_node_update().

File

./webform.module, line 994

Code

function webform_node_insert($node) {
  if (!in_array($node->type, webform_variable_get('webform_node_types'))) {
    return;
  }

  // If added directly through node_save(), set defaults for the node.
  if (!isset($node->webform)) {
    $node->webform = webform_node_defaults();
  }

  // Do not make an entry if this node does not have any Webform settings.
  if ($node->webform == webform_node_defaults() && !in_array($node->type, webform_variable_get('webform_node_types_primary'))) {
    return;
  }
  module_load_include('inc', 'webform', 'includes/webform.components');
  module_load_include('inc', 'webform', 'includes/webform.emails');

  // Insert the webform.
  $node->webform['nid'] = $node->nid;
  $node->webform['record_exists'] = (bool) drupal_write_record('webform', $node->webform);

  // Insert the components into the database. Used with clone.module.
  if (isset($node->webform['components']) && !empty($node->webform['components'])) {
    foreach ($node->webform['components'] as $cid => $component) {
      $component['nid'] = $node->nid;

      // Required for clone.module.
      webform_component_insert($component);
    }
  }

  // Insert emails. Also used with clone.module.
  if (isset($node->webform['emails']) && !empty($node->webform['emails'])) {
    foreach ($node->webform['emails'] as $eid => $email) {
      $email['nid'] = $node->nid;
      webform_email_insert($email);
    }
  }

  // Set the per-role submission access control.
  foreach (array_filter($node->webform['roles']) as $rid) {
    db_query('INSERT INTO {webform_roles} (nid, rid) VALUES (%d, %d)', $node->nid, $rid);
  }
}