function conditional_fields_save_field in Conditional Fields 6.2
Same name and namespace in other branches
- 6 conditional_fields.module \conditional_fields_save_field()
Handle saving of individual controlled field settings $controlling_fields is a keyed array of controlling fields names and trigger values
Use this function with caution, as it doesn't check if the content type and the fields actually exist.
2 calls to conditional_fields_save_field()
- conditional_fields_content_fieldapi in ./
conditional_fields.module - Implementation of hook_content_fieldapi().
- conditional_fields_forms_submit in ./
conditional_fields.module - Handle saving of conditional field settings. The controlled field can be either a field or a group
File
- ./
conditional_fields.module, line 1293 - Content fields and groups visibility based on the values of user defined 'trigger' fields.
Code
function conditional_fields_save_field($type_name, $controlled_field, $controlling_fields) {
foreach ($controlling_fields as $controlling_field => $trigger_values) {
// If the row already exists
if (db_result(db_query("SELECT COUNT(*) FROM {conditional_fields} WHERE control_field_name = '%s' AND field_name = '%s' AND type = '%s'", $controlling_field, $controlled_field, $type_name))) {
// If no value is set, delete the entry, else update it
if (empty($trigger_values) || !empty($trigger_values['conditional_field_no_value'])) {
conditional_fields_delete_field($type_name, $controlled_field, $controlling_field);
}
else {
conditional_fields_update_field($type_name, $controlled_field, $controlling_field, $trigger_values);
}
}
else {
// If values are set, create new entry
if (!empty($trigger_values) && empty($trigger_values['conditional_field_no_value'])) {
conditional_fields_insert_field($type_name, $controlled_field, $controlling_field, $trigger_values);
}
}
}
}