You are here

function jscalendar_form_alter in Javascript Tools 5

Implementation of hook_form_alter().

File

jscalendar/jscalendar.module, line 43
Provide popup calendar.

Code

function jscalendar_form_alter($form_id, &$form) {
  if ($form_id == 'comment_form' && isset($form['admin']) && isset($form['admin']['date'])) {
    $form['admin']['date']['#attributes'] = array(
      'class' => 'jscalendar',
    );
  }
  elseif (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id && isset($form['author']) && isset($form['author']['date'])) {
    $form['author']['date']['#attributes'] = array(
      'class' => 'jscalendar',
    );
  }
  foreach (element_children($form) as $key) {
    if (isset($form[$key]) && isset($form[$key]['#attributes']) && isset($form[$key]['#attributes']['class']) && !(strpos($form[$key]['#attributes']['class'], 'jscalendar') === FALSE)) {
      jscalendar_load();
      $settings = array(
        'ifFormat',
        'showsTime',
        'timeFormat',
      );
      foreach ($settings as $setting) {
        if (isset($form[$key]['#jscalendar_' . $setting])) {
          $form[$key . '_jscalendar']['#tree'] = TRUE;
          $form[$key . '_jscalendar'][$setting] = array(
            '#type' => 'hidden',
            '#value' => $form[$key]['#jscalendar_' . $setting],
          );
          unset($form[$key]['#jscalendar_' . $setting]);
        }
      }
    }

    // If necessary, recurse through all children.
    jscalendar_form_alter($form_id, $form[$key]);
  }
}