function partial_date_field_widget_reduce_date_components in Partial Date 7
Helper function to assign the correct components into an array that the formatters can use.
1 call to partial_date_field_widget_reduce_date_components()
- partial_date_field_formatter_view in ./
partial_date.module - Implements hook_field_formatter_view().
File
- ./
partial_date.module, line 349 - Defines a date element that allows for any combination of date granularity settings.
Code
function partial_date_field_widget_reduce_date_components($item, $is_start = TRUE, $is_approx = FALSE) {
if (empty($item)) {
return FALSE;
}
$components = array();
foreach (partial_date_components() as $key => $title) {
if (!empty($item[$key . '_estimate'])) {
list($start, $end) = explode('|', $item[$key . '_estimate']);
$components[$key] = $is_start ? $start : $end;
$components[$key . '_estimate'] = $item[$key . '_estimate'];
// We hit this on save, so we can not rely on the load set.
if (isset($item[$key . '_estimate_label'])) {
$components[$key . '_estimate_label'] = $item[$key . '_estimate_label'];
$components[$key . '_estimate_value'] = $item[$key . '_estimate_value'];
}
if (isset($item[$key . '_estimate_value'])) {
$components[$key . '_estimate_value'] = $item[$key . '_estimate_value'];
}
}
else {
$components[$key] = isset($item[$key]) && strlen($item[$key]) ? $item[$key] : NULL;
}
}
// No easy way to test a 0 value :{
$has_data = FALSE;
foreach ($components as $key => $value) {
if (strlen($value)) {
$has_data = TRUE;
break;
}
}
if (!$has_data) {
return FALSE;
}
return $components;
}