function webform_component_insert in Webform 7.4
Same name and namespace in other branches
- 5.2 webform_components.inc \webform_component_insert()
- 6.3 includes/webform.components.inc \webform_component_insert()
- 6.2 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.
Return value
false|int On success return identifier for the components within node. FALSE on failure
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 774 - 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);
}
$component['value'] = isset($component['value']) ? $component['value'] : NULL;
$component['required'] = isset($component['required']) ? $component['required'] : 0;
$component['extra']['private'] = isset($component['extra']['private']) ? $component['extra']['private'] : 0;
if (!isset($component['cid'])) {
if (lock_acquire('webform_component_insert_' . $component['nid'], 5)) {
$next_id_query = db_select('webform_component')
->condition('nid', $component['nid']);
$next_id_query
->addExpression('MAX(cid) + 1', 'cid');
$component['cid'] = $next_id_query
->execute()
->fetchField();
if ($component['cid'] == NULL) {
$component['cid'] = 1;
}
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;
}
}
db_insert('webform_component')
->fields(array(
'nid' => $component['nid'],
'cid' => $component['cid'],
'pid' => $component['pid'],
'form_key' => $component['form_key'],
'name' => $component['name'],
'type' => $component['type'],
'value' => (string) $component['value'],
'extra' => serialize($component['extra']),
'required' => $component['required'],
'weight' => $component['weight'],
))
->execute();
// Post-insert actions.
module_invoke_all('webform_component_insert', $component);
return $component['cid'];
}