You are here

function values_save in Values 7

Same name and namespace in other branches
  1. 6 values.module \values_save()

Saves a values object to the database.

Parameters

$value_set: A value set object with the following properties

  • name: The machine name of the value set
  • description: The human readable name of the value set
  • values: An array of arrays of value data: 'values' => array( array( 'key' => ... The key for the value, 'value' => ... The value, 'weight' => ... The value weight, ), ),
2 calls to values_save()
values_form_submit in ./values.module
Submits the values form.
values_import_form_submit in ./values.module
Submit function for value list import.
1 string reference to 'values_save'
values_schema in ./values.install
Implements hook_schema().

File

./values.module, line 856
API for managing reusable value sets.

Code

function values_save($value_set) {
  foreach ($value_set->data as $key => $data) {
    if (!strlen($data['value'])) {
      unset($value_set->data[$key]);
    }
  }
  usort($value_set->data, 'values_sort_by_weight');

  // Is this an update?
  if (db_query("SELECT * FROM {values_sets} WHERE name = :name", array(
    ':name' => $value_set->name,
  ))
    ->fetchObject()) {
    $update = 'name';
  }
  else {
    $update = array();
  }

  // Write to the database
  if ($success = drupal_write_record('values_sets', $value_set, $update)) {
    drupal_set_message(t('Value set !title was saved.', array(
      '!title' => $value_set->title,
    )));
  }
}