You are here

function _date_field_update in Date 6

Same name and namespace in other branches
  1. 5.2 date/date_elements.inc \_date_field_update()
  2. 6.2 date/date_elements.inc \_date_field_update()

Private implementation of hook_field update and insert operations.

1 call to _date_field_update()
date_field in date/date.module
Implementation of hook_field().

File

date/date_elements.inc, line 43
Date forms and form themes and validation.

Code

function _date_field_update($op, &$node, $field, &$items, $teaser, $page) {
  $field_name = $field['field_name'];
  $format = $field['type'] == DATE_ISO ? DATE_FORMAT_ISO : DATE_FORMAT_UNIX;
  $timezone = date_get_timezone($field['tz_handling'], $items[0]['timezone']);
  $db_info = content_database_info($field);
  $columns = array_keys($db_info['columns']);
  $values = $items;
  foreach ($values as $delta => $item) {

    // Don't save empty values.
    if (empty($item['value']) && $delta !== 0) {
      unset($items[$delta]);
    }

    // For convenience, we process all possible columns in the element,
    // but now we need to remove columns not used by this field.
    if (is_array($item)) {
      $keys = array_keys($item);
      foreach ($keys as $column => $value) {
        if (!in_array($column, $columns)) {
          unset($items[$delta][$column]);
        }
      }
    }

    // Special case for ISO dates which may have been given artificial values for
    // some date parts to make them into valid dates.
    if ($field['type'] == DATE_ISO) {
      $items[$delta]['value'] = date_limit_value($items[$delta]['value'], date_granularity($field), $field['type']);
      if ($field['todate']) {
        $items[$delta]['value2'] = date_limit_value($items[$delta]['value2'], date_granularity($field), $field['type']);
      }
    }
  }
  $node->{$field}['field_name'] = $items;
}