You are here

function event_form_alter in Event 5

Same name and namespace in other branches
  1. 5.2 event.module \event_form_alter()

File

./event.module, line 1876

Code

function event_form_alter($form_id, &$form) {
  global $user;
  $node = isset($form['#node']) ? $form['#node'] : NULL;
  switch ($form_id) {

    // node settings form
    case 'node_type_form':
      $type = isset($form['old_type']) && isset($form['old_type']['#value']) ? $form['old_type']['#value'] : NULL;
      $form['workflow']['event_nodeapi'] = array(
        '#type' => 'radios',
        '#title' => t('Show in event calendar'),
        '#default_value' => variable_get('event_nodeapi_' . $type, 'never'),
        '#options' => array(
          'all' => t('All views'),
          'solo' => t('Only in views for this type'),
          'never' => t('Never'),
        ),
        '#description' => t('All views: This content type will be available for display on all calendar views, including with other events.<br />Only in views for this type: This content type will only appear in calendar views specific to this type and never with other events.<br />Never: This content type will not be associated with the events calendar.'),
      );
      break;

    // node edit form
    case $form['type']['#value'] . '_node_form':
      if (variable_get('event_nodeapi_' . $form['type']['#value'], 'never') != 'never') {
        include_once EVENT_PATH . '/event_timezones.inc';

        /**
         *  Check to see if jscalendar is installed
         *  If so, display it, otherwise default to normal drop-down list selectors
         */
        if (module_exists('jscalendar')) {
          $form['start_date'] = array(
            '#title' => t('Start Date'),
            '#type' => 'textfield',
            '#default_value' => _event_date('Y-m-d H:i', $node->event_start ? $node->event_start : _event_user_time(), $node->start_offset),
            '#attributes' => array(
              'class' => 'jscalendar',
            ),
            '#jscalendar_ifFormat' => '%Y-%m-%d %H:%M',
            '#jscalendar_showsTime' => 'true',
            '#jscalendar_timeFormat' => variable_get('event_ampm', '0') == 0 ? '24' : '12',
            '#size' => 19,
            '#maxlength' => 19,
            '#weight' => -15,
            '#description' => t('YYYY-MM-DD HH:MM'),
          );
          $form['end_date'] = array(
            '#title' => t('End Date'),
            '#type' => 'textfield',
            '#default_value' => _event_date('Y-m-d H:i', $node->event_end ? $node->event_end : _event_user_time(), $node->end_offset),
            '#attributes' => array(
              'class' => 'jscalendar',
            ),
            '#jscalendar_ifFormat' => '%Y-%m-%d %H:%M',
            '#jscalendar_showsTime' => 'true',
            '#jscalendar_timeFormat' => variable_get('event_ampm', '0') == 0 ? '24' : '12',
            '#size' => 19,
            '#maxlength' => 19,
            '#weight' => -14,
            '#description' => t('YYYY-MM-DD HH:MM'),
          );
        }
        else {
          $form['event_start'] = array(
            '#type' => 'fieldset',
            '#title' => t('Start date'),
            '#weight' => -15,
          );
          $form['event_start']['date'] = event_form_date($node->event_start ? $node->event_start : _event_user_time(), 'start', $node->start_offset);
          $form['event_end'] = array(
            '#type' => 'fieldset',
            '#title' => t('End date'),
            '#weight' => -14,
          );
          $form['event_end']['date'] = event_form_date($node->event_end ? $node->event_end : _event_user_time(), 'end', $node->end_offset);
        }
        if (variable_get('event_timezone_input', 'site') == 'input') {
          $form['timezone'] = array(
            '#type' => 'select',
            '#title' => t('Time zone'),
            '#default_value' => $node->timezone ? $node->timezone : event_timezone_map(variable_get('date_default_timezone', 0)),
            '#options' => event_zonelist(),
            '#description' => t('Select the time zone this event occurs in.'),
            '#weight' => -13,
          );
        }
        elseif (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone) && variable_get('event_timezone_input', 'site') == 'user') {
          $form['timezone'] = array(
            '#type' => 'hidden',
            '#value' => event_timezone_map($user->timezone),
          );
        }
        else {
          $form['timezone'] = array(
            '#type' => 'hidden',
            '#value' => event_timezone_map(variable_get('date_default_timezone', 0)),
          );
        }
      }
      break;
  }
}