function _date_repeat_widget_validate in Date 7
Same name and namespace in other branches
- 5.2 date/date_repeat.inc \_date_repeat_widget_validate()
- 6.2 date/date_repeat.inc \_date_repeat_widget_validate()
- 6 date/date_repeat.inc \_date_repeat_widget_validate()
Validation for date repeat form element.
Create multiple values from the RRULE results. Lots more work needed here.
1 call to _date_repeat_widget_validate()
- date_widget_validate in ./
date_elements.inc - Handle widget processing.
File
- ./
date_repeat.inc, line 55 - Implementation of Date Repeat API calculations for the CCK Date field.
Code
function _date_repeat_widget_validate($element, &$form_state) {
module_load_include('inc', 'date_repeat', 'date_repeat_form');
$field_name = $element['#field_name'];
$field = field_widget_field($element, $form_state);
$instance = field_widget_instance($element, $form_state);
$form_values = $form_state['values'];
$item = $form_values;
$input = $form_state['input'];
foreach ($element['#parents'] as $key) {
$item = $item[$key];
$input = $input[$key];
}
$rrule_values = date_repeat_merge($input['rrule'], $element['rrule']);
// If no start date was set, clean up the form and return.
// If no repeats are set, clean up the form and return.
if (empty($item['value']) || $rrule_values['FREQ'] == 'NONE') {
$item['rrule'] = NULL;
form_set_value($element, array(
$item,
), $form_state);
return;
}
// Require the UNTIL date for now.
// The RRULE has already been created by this point, so go back
// to the posted values to see if this was filled out.
$error_field = implode('][', $element['#parents']) . '][rrule][UNTIL][datetime][date';
if (empty($rrule_values['UNTIL']['datetime'])) {
form_set_error($error_field, t('The UNTIL value is required for repeating dates.'));
}
if (form_get_errors()) {
return;
}
// If the rule, the start date, or the end date have changed, re-calculate
// the repeating dates, wipe out the previous values, and populate the
// field with the new values.
// TODO
// Is it right to not do anything unless there are changes? Will that
// confuse anyone? Commenting that out for now...
$rrule = $item['rrule'];
if (!empty($rrule)) {
// Avoid undefined index problems on dates that don't have all parts.
$possible_items = array(
'value',
'value2',
'timezone',
'offset',
'offset2',
);
foreach ($possible_items as $key) {
if (empty($item[$key])) {
$item[$key] = '';
}
}
$value = date_repeat_build_dates($rrule, $rrule_values, $field, $item);
form_set_value($element, $value, $form_state);
}
else {
// If no changes are needed, move the RRULE back to the zero value
// item of the field.
form_set_value(array(
'#parents' => array(
$field_name,
$element['#language'],
0,
'rrule',
),
), $rrule, $form_state);
form_set_value($element, NULL, $form_state);
}
}