function datex_date_date_select_process_alter in Datex 7
Implements hook date_select_process_alter().
Converts Gregorian date to Jalali date before displaying it in Form API. (such as node edit form).
File
- datex_date/
datex_date.module, line 53 - Provides Jalali support for date module.
Code
function datex_date_date_select_process_alter(&$element, &$form_state, $context) {
if (_datex_skip_language()) {
return;
}
$persian_date_names = DatexFormatter::persianDateNames();
$y =& $element['year']['#default_value'];
$m =& $element['month']['#default_value'];
$d =& $element['day']['#default_value'];
$default = DatexFormatter::toJalali($y, $m, $d);
if (!empty($y)) {
$y = $default['year'];
}
if (!empty($m)) {
$m = $default['month'];
}
if (!empty($d)) {
$d = $default['day'];
}
// Generating Year Option (if field has year granularity):
if (in_array('year', $element['#granularity'])) {
list($year_before, $year_after) = explode(':', $element['#date_year_range']);
$element['year']['#options'] = array();
// If year field is not required, add an empty value as drupal does.
if (!$element['#required']) {
$element['year']['#options'][''] = '';
}
// Now add actual year options.
$year_now = DatexObjectUtils::getYear();
for ($year = $year_now + intval($year_before); $year <= $year_now + intval($year_after); $year++) {
$element['year']['#options'][$year] = $year;
}
}
// Generating month Option (if field has month granularity).
if (in_array('month', $element['#granularity'])) {
$element['month']['#options'] = array();
// If field is not required, add an empty value as drupal does.
if (!$element['#required']) {
$element['month']['#options'][''] = '';
}
// Now add month options.
for ($i = 1; $i < 13; $i++) {
$element['month']['#options'][$i] = $persian_date_names['months'][$i];
}
}
}