The overall workflow for i18n is usually as follows:

(For date popup field)

1. hook_date_popup_process_alter -> Localize dates from Gregorian to any desired calendars.
2. User sees localized date, selects a localized date, and submits a localized date.
3. Validation callback is called: my_custom_module_date_popup_validation_callback (registered for date-popup via hook_element_info_alter to happen *before* date's original validation callback).
4. Convert localized dates back into Gregorian in the validation callback. Date module will handle the rest.

However multiple scenarios need to be handles:

1. The field is/is not required.
2. The field has/has not default value.
3. The user enters/does not enter a value.
4. The form the field is on, has/has not errors.

Which makes upto 2*2*2*2=16 cases and is a bit confusing. Dates are stored in multiple places (from hook_date_popup_process_alter($element, $form_state)):

1. $form_state['values'][...element path...]
2. $form_state['input'][...element path...]
3. $element['date']['#value']
4. $element['date']['#default_value']
5. $element['#value']
6. $element['#default_value'] // This one is only used internally, we don't touch.

Also, 1 to 5 also exist in validation callback. Could you guide me how to do it properly? according to 16 cases, How can I know when to convert 1to5 from/to Gregorian?

(This also true for date_select and date_text fields).

Thanks.

Comments

loolooyyyy created an issue. See original summary.

hkoosha’s picture

Status: Active » Closed (outdated)