function date_combo_process in Date 6.2
Same name and namespace in other branches
- 5.2 date/date_elements.inc \date_combo_process()
- 6 date/date_elements.inc \date_combo_process()
Process an individual date element.
1 string reference to 'date_combo_process'
- _date_elements in date/
date_elements.inc - Implementation of hook_elements().
File
- date/
date_elements.inc, line 252 - Date forms and form themes and validation.
Code
function date_combo_process($element, $edit, &$form_state, $form) {
if (isset($element['#access']) && empty($element['#access'])) {
return $element;
}
$field_name = $element['#field_name'];
$field = $form['#field_info'][$field_name];
$delta = $element['#delta'];
$columns = $element['#columns'];
if (isset($columns['rrule'])) {
unset($columns['rrule']);
}
$from_field = 'value';
$to_field = 'value2';
$tz_field = 'timezone';
$offset_field = 'offset';
$offset_field2 = 'offset2';
if ($field['todate'] != 'required' && !empty($element['#default_value'][$to_field]) && $element['#default_value'][$to_field] == $element['#default_value'][$from_field]) {
unset($element['#default_value'][$to_field]);
}
$element[$from_field] = array(
'#field' => $field,
'#title' => !$field['multiple'] || $field['repeat'] ? t($field['widget']['label']) : '',
'#weight' => $field['widget']['weight'],
'#required' => $field['required'] && $delta == 0 ? 1 : 0,
'#default_value' => isset($element['#value'][$from_field]) ? $element['#value'][$from_field] : '',
'#delta' => $delta,
'#date_timezone' => $element['#date_timezone'],
'#date_format' => date_limit_format(date_input_format($element, $field), $field['granularity']),
'#date_text_parts' => (array) $field['widget']['text_parts'],
'#date_increment' => $field['widget']['increment'],
'#date_year_range' => $field['widget']['year_range'],
'#date_label_position' => $field['widget']['label_position'],
);
$description = !empty($field['widget']['description']) ? t($field['widget']['description']) : '';
// Give this element the right type, using a Date API
// or a Date Popup element type.
switch ($field['widget']['type']) {
case 'date_select':
case 'date_select_repeat':
// From/to selectors with lots of parts will look better if displayed
// on two rows instead of in a single row.
if (!empty($field['todate']) && count($field['granularity']) > 3) {
$element[$from_field]['#attributes'] = array(
'class' => 'date-clear',
);
}
$element[$from_field]['#type'] = 'date_select';
break;
case 'date_popup':
case 'date_popup_repeat':
$element[$from_field]['#type'] = 'date_popup';
break;
default:
$element[$from_field]['#type'] = 'date_text';
break;
}
// If this field uses the 'To', add matching element
// for the 'To' date, and adapt titles to make it clear which
// is the 'From' and which is the 'To'.
if (!empty($field['todate'])) {
$element['#date_float'] = TRUE;
$element[$from_field]['#title'] = t('From date');
$element[$to_field] = $element[$from_field];
$element[$to_field]['#title'] = t('To date');
$element[$to_field]['#default_value'] = isset($element['#value'][$to_field]) ? $element['#value'][$to_field] : '';
$element[$to_field]['#required'] = FALSE;
$element[$to_field]['#weight'] += 0.1;
if ($field['widget']['type'] == 'date_select' && empty($description)) {
$description = t("Empty 'To date' values will use the 'From date' values.");
}
else {
if (trim($description) == "") {
$description = NULL;
}
}
$element['#fieldset_description'] = $description;
}
else {
$element[$from_field]['#description'] = $description;
}
// Create label for error messages that make sense in multiple values
// and when the title field is left blank.
if (!empty($field['multiple']) && empty($field['repeat'])) {
$element[$from_field]['#date_title'] = t('@field_name From date value #@delta', array(
'@field_name' => $field['widget']['label'],
'@delta' => $delta + 1,
));
if (!empty($field['todate'])) {
$element[$to_field]['#date_title'] = t('@field_name To date value #@delta', array(
'@field_name' => $field['widget']['label'],
'@delta' => $delta + 1,
));
}
}
elseif (!empty($field['todate'])) {
$element[$from_field]['#date_title'] = t('@field_name From date', array(
'@field_name' => $field['widget']['label'],
));
$element[$to_field]['#date_title'] = t('@field_name To date', array(
'@field_name' => $field['widget']['label'],
));
}
else {
$element[$from_field]['#date_title'] = $field['widget']['label'];
}
// Make sure field info will be available to the validator which
// does not get the values in $form.
$form_state['#field_info'][$field['field_name']] = $field;
return $element;
}