function flexslider_optionset_save in Flex Slider 7.2
Same name and namespace in other branches
- 7 flexslider.module \flexslider_optionset_save()
Saves the given option set to the database. Set the $new flag if this set has not been written before.
Return value
object|boolean Returns the newly saved object, FALSE otherwise.
3 calls to flexslider_optionset_save()
- FlexsliderTestCase::testOptionSetCrud in ./
flexslider.test - flexslider_form_optionset_add_submit in ./
flexslider.admin.inc - Submit handler for adding a new option set.
- flexslider_update_7200 in ./
flexslider.install - Migrate settings from FlexSlider v1 to v2
File
- ./
flexslider.module, line 301 - A light-weight, customizable image gallery plugin for Drupal based on jQuery
Code
function flexslider_optionset_save($optionset, $new = FALSE) {
// If the machine name is missing or already in use, return an error.
if (empty($optionset->name) or FALSE != flexslider_optionset_exists($optionset->name) and $new) {
return FALSE;
}
// Check for an invalid list of options
if (isset($optionset->options) and !is_array($optionset->options)) {
return FALSE;
}
// If the title is missing, default to the name
if (empty($optionset->title)) {
$optionset->title = $optionset->name;
}
// Merge default settings with any given settings
$optionset_defaults = _flexslider_optionset_defaults();
$optionset->options = $optionset->options + $optionset_defaults;
_flexslider_typecast_optionset($optionset->options);
// Prepare the database values.
$db_values = array(
'name' => $optionset->name,
'title' => $optionset->title,
'options' => $optionset->options,
);
if ($new) {
$result = drupal_write_record('flexslider_optionset', $db_values);
}
else {
$result = drupal_write_record('flexslider_optionset', $db_values, 'name');
}
// Return the object if the values were saved successfully.
if ($new and SAVED_NEW == $result or !$new and SAVED_UPDATED == $result) {
return $optionset;
}
// Otherwise, an error occurred
return FALSE;
}