function date_field_presave in Date 8
Same name and namespace in other branches
- 7.3 date.field.inc \date_field_presave()
- 7 date.field.inc \date_field_presave()
- 7.2 date.field.inc \date_field_presave()
Implements hook_field_insert().
File
- ./
date.field.inc, line 132 - Field hooks to implement a date field.
Code
function date_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
$field_name = $field['field_name'];
if (empty($items)) {
return;
}
// Add some information needed to interpret token values.
$values = $items;
foreach ($values as $delta => $item) {
$timezone = isset($item['timezone']) ? $item['timezone'] : '';
if (is_array($item)) {
$items[$delta]['timezone'] = date_get_timezone($field['settings']['tz_handling'], $timezone);
$items[$delta]['timezone_db'] = date_get_timezone_db($field['settings']['tz_handling']);
$items[$delta]['date_type'] = $field['type'];
$data = array();
foreach (date_data_keys() as $key) {
if (isset($item[$key])) {
$data[$delta][$key] = $item[$key];
unset($items[$delta][$key]);
}
}
$items[$delta]['data'] = serialize($data);
}
}
$entity->{$field['field_name']}[$langcode] = $items;
}