function date_field_field_presave in Date 8
Implements hook_field_insert().
File
- date_field/
date_field.module, line 134
Code
function date_field_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;
}