You are here

function fasttoggle_field_save in Fasttoggle 7

Save a new field value.

Parameters

array $options: The array of configuration options.

string $group: The setting group string.

string $instance: The setting instance string.

object $object: The object from which to get the value.

1 string reference to 'fasttoggle_field_save'
fasttoggle_field_fasttoggle_available_links in module/fasttoggle_field/fasttoggle_field.module
Implements hook_fasttoggle_available_links().

File

module/fasttoggle_field/fasttoggle_field.module, line 226

Code

function fasttoggle_field_save(array $options, $group, $instance, $new_value, $object) {
  $label_settings = $options['fields'][$group]['instances'][$instance];
  $values_array = $label_settings['labels'][FASTTOGGLE_LABEL_STATUS];
  $keys = array_keys($values_array);

  // If the data value is optional, the last value is the 'unset' value.
  $last_value = array_pop($keys);
  if ($label_settings['optional'] && (string) $new_value === (string) $last_value) {
    $object->{$instance} = array();
  }
  else {
    $object->{$instance}[LANGUAGE_NONE][0]['value'] = $new_value;
  }
  field_attach_update($options['object_type'], $object);
}