function webform_validation_rule_save in Webform Validation 7
Same name and namespace in other branches
- 6 webform_validation.module \webform_validation_rule_save()
Save a validation rule.
Data comes from the admin form or nodeapi function in case of node clone.
Parameters
array $values: An associative array containing:
- action: "add" or "edit".
- ruleid: ID of the rule to edit. Do not set for "add".
- nid: Node ID of the Webform.
- validator: Machine name of the validator used by this validation rule.
- rulename: Human-readable name for this validation rule.
- rule_components: An array in which the keys and the values are the cid's of the Webform components that this rule applies to.
Return value
int The $ruleid of the rule added or edited.
3 calls to webform_validation_rule_save()
- webform_validation_entity_uuid_save in ./
webform_validation.module - Implements hook_entity_uuid_save().
- webform_validation_manage_rule_submit in ./
webform_validation.admin.inc - Submit handler to add / edit a rule.
- webform_validation_node_clone in ./
webform_validation.module - Adds support for node_clone module.
File
- ./
webform_validation.module, line 487
Code
function webform_validation_rule_save(array $values) {
if ($values['action'] === 'add') {
$primary_keys = array();
}
elseif ($values['action'] === 'edit') {
$primary_keys = array(
'ruleid',
);
}
else {
return FALSE;
}
$transaction = db_transaction();
drupal_write_record('webform_validation_rule', $values, $primary_keys);
// Delete existing component records for this ruleid.
if ($values['action'] === 'edit') {
db_delete('webform_validation_rule_components')
->condition('ruleid', $values['ruleid'])
->execute();
}
$components = array_filter($values['rule_components']);
if ($values['ruleid'] && $components) {
webform_validation_save_rule_components($values['ruleid'], $components);
module_invoke_all('webform_validation', 'rule', $values['action'], $values);
}
return $values['ruleid'];
}