为什么不使用 hook_node_insert?
这是为每个新的网络表单添加组件的工作示例:
/**
* Implements hook_node_insert().
*/
function modulename_node_insert($node) {
if($node->type == 'webform' && $node->is_new) {
module_load_include('inc', 'webform', 'includes/webform.components');
$components = array();
$components[0] = array(
'name' => 'Submitted Page URL',
'nid' => $node->nid,
'form_key' => 'hidden_submitted_page_url',
'type' => 'hidden',
'mandatory' => 0,
'weight' => 99,
'pid' => 0,
'value' => '',
'required' => 0,
'extra' => array(
'hidden_type' => 'hidden',
'description' => '',
'wrapper_classes' => 'hidden-submitted-page-url-wrap',
'css_classes' => 'hidden-submitted-page-url',
'private' => 0,
),
);
$components[1] = array(
'name' => 'Referrer Page URL',
'nid' => $node->nid,
'form_key' => 'hidden_referrer_page_url',
'type' => 'hidden',
'mandatory' => 0,
'weight' => 99,
'pid' => 0,
'value' => '',
'required' => 0,
'extra' => array(
'hidden_type' => 'hidden',
'description' => '',
'wrapper_classes' => 'hidden-referrer-page-url-wrap',
'css_classes' => 'hidden-referrer-page-url',
'private' => 0,
),
);
foreach ($components as $component) {
webform_component_insert($component);
}
}
}