You are here

function calendar_systems_form_alter in Calendar Systems 8

Same name and namespace in other branches
  1. 5 calendar_systems.module \calendar_systems_form_alter()
  2. 6.3 calendar_systems.module \calendar_systems_form_alter()
  3. 6 calendar_systems.module \calendar_systems_form_alter()
  4. 7.3 calendar_systems.module \calendar_systems_form_alter()
  5. 7 calendar_systems.module \calendar_systems_form_alter()
  6. 7.2 calendar_systems.module \calendar_systems_form_alter()

Implements hook_form_alter().

@todo Extend, fix.

File

./calendar_systems.module, line 293
Contains Calendar Systems hook implementations and helpers.

Code

function calendar_systems_form_alter(&$form, $form_state, $form_id) {
  if (calendar_systems_get_calendar_system_name() != 'default') {

    // Overwrite date field element validate callback:
    if (@isset($form['scheduler_settings']['publish_on'])) {
      $form['scheduler_settings']['publish_on']['#element_validate'] = array_merge(array(
        'calendar_systems_date_validate',
      ), (array) @$form['author']['date']['#element_validate']);
      if (variable_get('calendar_systems_js_date_picker_core_text_date_fields')) {
        $form['scheduler_settings']['publish_on']['#attributes']['class'][] = 'calendar_systems_js_date_picker';
        calendar_systems_attach_js_date_picker($form['scheduler_settings']['publish_on'], 'Y-m-d', 'H:i:s');
      }
    }
    if (@isset($form['scheduler_settings']['unpublish_on'])) {
      $form['scheduler_settings']['unpublish_on']['#element_validate'] = array_merge(array(
        'calendar_systems_date_validate',
      ), (array) @$form['author']['date']['#element_validate']);
      if (variable_get('calendar_systems_js_date_picker_core_text_date_fields')) {
        $form['scheduler_settings']['unpublish_on']['#attributes']['class'][] = 'calendar_systems_js_date_picker';
        calendar_systems_attach_js_date_picker($form['scheduler_settings']['unpublish_on'], 'Y-m-d', 'H:i:s');
      }
    }
    if (isset($form['author']['date'])) {
      $form['author']['date']['#element_validate'] = array_merge(array(
        'calendar_systems_date_validate',
      ), (array) @$form['author']['date']['#element_validate']);
      if (variable_get('calendar_systems_js_date_picker_core_text_date_fields')) {
        $form['author']['date']['#attributes']['class'][] = 'calendar_systems_js_date_picker';
        calendar_systems_attach_js_date_picker($form['author']['date'], 'Y-m-d', 'H:i:s');
      }
    }
    if (isset($form['translation']['created'])) {
      $form['translation']['created']['#element_validate'] = array_merge(array(
        'calendar_systems_date_validate',
      ), (array) @$form['author']['date']['#element_validate']);
      if (variable_get('calendar_systems_js_date_picker_core_text_date_fields')) {
        $form['translation']['created']['#attributes']['class'][] = 'calendar_systems_js_date_picker';
        calendar_systems_attach_js_date_picker($form['translation']['created'], 'Y-m-d', 'H:i:s');
      }
    }
    if (isset($form['admin']['date'])) {
      $form['admin']['date']['#element_validate'] = array_merge(array(
        'calendar_systems_date_validate',
      ), (array) @$form['admin']['date']['#element_validate']);
      if (variable_get('calendar_systems_js_date_picker_core_text_date_fields')) {
        $form['admin']['date']['#attributes']['class'][] = 'calendar_systems_js_date_picker';
        calendar_systems_attach_js_date_picker($form['admin']['date'], 'Y-m-d', 'H:i:s');
      }
    }
    if ($form_id == 'views_exposed_form') {
      $form['#validate'] = array_merge($form['#validate'], array(
        '_calendar_systems_views_exposed_form_validate',
      ));
    }
    if (isset($form['submitted']) && isset($form['#process']) && is_array($form['#process']) && in_array('webform_client_form_includes', $form['#process'])) {
      $form['submitted']['test']['#process'][] = '_calendar_systems_element_date_process';
      $form['submitted']['test']['#element_validate'] = array_merge(array(
        'calendar_systems_date_validate',
      ), (array) $form['submitted']['test']['#element_validate']);
    }
    if (!_calendar_systems_is_patch_applied()) {
      $calendar = calendar_systems_get_calendar_instance();
      $format = variable_get('date_format_medium');
      if (isset($form['scheduler_settings'])) {
        foreach (array(
          'publish_on',
          'unpublish_on',
        ) as $name) {
          if (isset($form['#node']->scheduler[$name]) && !empty($form['scheduler_settings'][$name]['#default_value'])) {
            $form['scheduler_settings'][$name]['#default_value'] = $calendar
              ->smartGet('Y-m-d H:i:s O', $form['#node']->scheduler[$name]);
          }
          $form['scheduler_settings'][$name]['#description'] = t('Format: %date The date format is YYYY-MM-DD and time is H:i:s. Leave blank to disable scheduled.', array(
            '%date' => $now,
          ));
        }
      }
      if (isset($form['author']['date']) && isset($form_state['node'])) {
        $node =& $form_state['node'];
        $form['author']['date']['#description'] = t('Format: %time. The date format is YYYY-MM-DD and %timezone is the time zone offset from UTC. Leave blank to use the time of form submission.', array(
          '%time' => !empty($node->date) ? $calendar
            ->smartGet('Y-m-d H:i:s O', $node->date) : $calendar
            ->smartGet('Y-m-d H:i:s O', $node->created),
          '%timezone' => !empty($node->date) ? $calendar
            ->smartGet('O', $node->date) : $calendar
            ->smartGet('O', $node->created),
        ));
        if (!empty($form['author']['date']['#default_value'])) {
          $form['author']['date']['#default_value'] = $calendar
            ->smartGet('Y-m-d H:i:s O', $form['created']['#value']);
        }
      }
    }
  }
}