function _date_widget_settings in Date 5.2
Same name and namespace in other branches
- 5 date_admin.inc \_date_widget_settings()
- 6.2 date/date_admin.inc \_date_widget_settings()
- 6 date/date_admin.inc \_date_widget_settings()
Implementation of hook_widget_settings().
1 call to _date_widget_settings()
- date_widget_settings in date/
date.module - Wrapper functions for date administration, included only when processing field settings.
File
- date/
date_admin.inc, line 10 - Date administration code. Moved to separate file since there is a lot of code here that is not needed often.
Code
function _date_widget_settings($op, &$field) {
switch ($op) {
case 'callbacks':
return array(
'default value' => CONTENT_CALLBACK_CUSTOM,
);
case 'form':
return date_widget_settings_form($field);
case 'save':
return array(
'default_value',
'default_value_code',
'default_value2',
'default_value_code2',
'input_format',
'input_format_custom',
'increment',
'text_parts',
'year_range',
'label_position',
);
case 'validate':
if ($field['default_value'] == 'strtotime') {
$is_strtotime = @strtotime($field['default_value_code']);
if (!$is_strtotime) {
form_set_error('default_value_code', t('The Strtotime default value is invalid.'));
}
}
if ($field['default_value2'] == 'strtotime') {
$is_strtotime = @strtotime($field['default_value_code2']);
if (!$is_strtotime) {
form_set_error('default_value_code2', t('The Strtotime default value for the To Date is invalid.'));
}
}
if ($field['widget_type'] == 'date_select' && !preg_match('@\\-[0-9]*:[\\+|\\-][0-9]*@', $field['year_range'])) {
form_set_error('year_range', t('Years back and forward must be in the format -9:+9.'));
}
if ($field['widget_type'] == 'date_popup') {
// Only a limited set of formats is available for the Date Popup module
if (!empty($field['input_format_custom']) || !in_array($field['input_format'], date_popup_formats())) {
form_set_value(array(
'#parents' => array(
'input_format_custom',
),
), NULL);
form_set_value(array(
'#parents' => array(
'input_format',
),
), DATE_FORMAT_DATETIME);
}
// The jQuery calendar requires year, month, and day or it won't work.
$date_parts = array(
'year',
'month',
'day',
);
$intersection = array_intersect($date_parts, $field['granularity']);
if ($intersection != $date_parts) {
form_set_error('granularity', t('The Date Popup widget will not work unless granularity includes year, month, and day.'));
}
}
if (isset($field['advanced']['label_position'])) {
form_set_value(array(
'#parents' => array(
'label_position',
),
), $field['advanced']['label_position']);
}
// Munge the table display for text parts back into an array of text parts.
if (is_array($field['advanced']['text_parts'])) {
form_set_value(array(
'#parents' => array(
'text_parts',
),
), array_keys(array_filter($field['advanced']['text_parts'])));
}
break;
}
}