function partial_date_field_load in Partial Date 7
Implements hook_field_load().
File
- ./
partial_date.module, line 124 - Defines a date element that allows for any combination of date granularity settings.
Code
function partial_date_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {
$has_range = strpos($field['type'], '_range');
$estimates = partial_date_field_estimates($field);
foreach ($entities as $id => $entity) {
foreach ($items[$id] as $delta => &$item) {
$settings = $instances[$id]['widget']['settings'];
// Generate a cleaner array based storage of the values.
$item['data'] = empty($item['data']) ? array() : unserialize($item['data']);
$item['from'] = array();
if ($has_range) {
$item['to'] = array();
}
$item['check_approximate'] = empty($item['data']['check_approximate']) ? 0 : 1;
foreach (partial_date_components() as $key => $title) {
$item['from'][$key] = $item[$key];
// Clear auto-populated estimate values.
if (!empty($item['data'][$key . '_estimate_from_used'])) {
$item['from'][$key] = '';
}
unset($item[$key]);
if ($key != 'timezone') {
$item['from'][$key . '_estimate'] = isset($item['data'][$key . '_estimate']) ? $item['data'][$key . '_estimate'] : '';
_partial_date_expand_estimate($key, $item['from'], $estimates);
}
if ($has_range) {
$item['to'][$key] = $item[$key . '_to'];
unset($item[$key . '_to']);
// Clear auto-populated estimate values.
if (!empty($item['data'][$key . '_estimate_to_used'])) {
$item['to'][$key] = '';
}
if ($key != 'timezone') {
$item['to'][$key . '_estimate'] = isset($item['data'][$key . '_to_estimate']) ? $item['data'][$key . '_to_estimate'] : '';
_partial_date_expand_estimate($key, $item['to'], $estimates, FALSE);
}
}
}
}
}
}