You are here

function slick_optionset_save in Slick Carousel 7.2

Saves the given option set to the database.

Set the $new flag if this set has not been written before.

Parameters

object $optionset: The Optionset object.

bool $new: The Optionset machine name.

Return value

object Returns the newly saved object, FALSE otherwise.

2 calls to slick_optionset_save()
SlickTestCase::testOptionSetCrud in tests/slick.test
Tests Slick optionset CRUD.
slick_update_7007 in ./slick.install
Typecast old optionset values (pre-alpha -- 2015-03-31).

File

includes/slick.admin.inc, line 188
Contains optional functions called only if needed by admin pages.

Code

function slick_optionset_save($optionset, $new = FALSE) {

  // If the machine name is missing or already in use, return an error.
  if (empty($optionset->name) or FALSE != slick_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 (empty($optionset->label)) {
    $optionset->label = $optionset->name;
  }

  // Merge default settings with any given settings.
  $breakpoints = 0;
  if (isset($optionset->breakpoints)) {
    $breakpoints = $optionset->breakpoints;
  }
  $defaults['general'] = array(
    'goodies' => array(),
  );
  $defaults['settings'] = slick_get_options();
  $optionset->options = $optionset->options + $defaults;
  _slick_typecast_optionset($optionset->options, $breakpoints);

  // Prepare the database values.
  $db_values = array(
    'name' => $optionset->name,
    'label' => $optionset->label,
    'breakpoints' => $breakpoints,
    'options' => $optionset->options,
  );
  if ($new) {
    $result = drupal_write_record('slick_optionset', $db_values);
  }
  else {
    $result = drupal_write_record('slick_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 occured.
  return FALSE;
}