function webform_component_insert in Webform 6.3
Same name and namespace in other branches
- 5.2 webform_components.inc \webform_component_insert()
- 6.2 webform_components.inc \webform_component_insert()
- 7.4 includes/webform.components.inc \webform_component_insert()
- 7.3 includes/webform.components.inc \webform_component_insert()
Insert a new component into the database.
Parameters
$component: A full component containing fields from the component form.
4 calls to webform_component_insert()
- webform_component_clone in includes/
webform.components.inc - Recursively insert components into the database.
- webform_component_edit_form_submit in includes/
webform.components.inc - Submit handler for webform_component_edit_form().
- webform_node_insert in ./
webform.module - Implements hook_node_insert().
- webform_node_update in ./
webform.module - Implements hook_node_update().
File
- includes/
webform.components.inc, line 741 - Webform module component handling.
Code
function webform_component_insert(&$component) {
// Allow modules to modify the component before saving.
foreach (module_implements('webform_component_presave') as $module) {
$function = $module . '_webform_component_presave';
$function($component);
}
if (lock_acquire('webform_component_insert_' . $component['nid'], 5)) {
$component['cid'] = isset($component['cid']) ? $component['cid'] : db_result(db_query('SELECT MAX(cid) FROM {webform_component} WHERE nid = %d', $component['nid'])) + 1;
$component['value'] = isset($component['value']) ? $component['value'] : NULL;
$component['mandatory'] = isset($component['mandatory']) ? $component['mandatory'] : 0;
$component['extra']['private'] = isset($component['extra']['private']) ? $component['extra']['private'] : 0;
db_query("INSERT INTO {webform_component} (nid, cid, pid, form_key, name, type, value, extra, mandatory, weight) VALUES (%d, %d, %d, '%s', '%s', '%s', '%s', '%s', %d, %d)", $component['nid'], $component['cid'], $component['pid'], $component['form_key'], $component['name'], $component['type'], $component['value'], serialize($component['extra']), $component['mandatory'], $component['weight']);
lock_release('webform_component_insert_' . $component['nid']);
}
else {
watchdog('webform', 'A Webform component could not be saved because a timeout occurred while trying to acquire a lock for the node. Details: <pre>@component</pre>', array(
'@component' => print_r($component, TRUE),
));
return FALSE;
}
// Post-insert actions.
module_invoke_all('webform_component_insert', $component);
return $component['cid'];
}