You are here

function event_form_alter in Event 5.2

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

Implementation of hook_form_alter

File

./event.module, line 1965

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') {
        $form['event']['has_time'] = array(
          '#type' => 'checkbox',
          '#title' => t('Event has time'),
          '#default_value' => !isset($node->event['has_time']) ? 1 : $node->event['has_time'],
          '#weight' => -16,
          '#description' => t('Is time important for this event? Uncheck if event takes all day.'),
        );
        $form['event']['has_end_date'] = array(
          '#type' => 'checkbox',
          '#title' => t('Event has end date'),
          '#default_value' => $node->event['has_end_date'],
          '#weight' => -14,
          '#description' => t('Check if you want to specify end date for this event, then choose end date below.'),
        );

        // We need to check if the timezone ID was set
        if (variable_get('date_default_timezone_id', 0) === 0) {
          drupal_set_message(t('Please <a href="!url">select the default timezone</a> for your website before creating events.', array(
            '!url' => url('admin/settings/date-time'),
          )), 'error');
        }

        /**
         *  Check to see if jscalendar is installed
         *  If so, display it, otherwise default to normal drop-down list selectors
         */
        if (module_exists('jscalendar')) {
          if (isset($node->event)) {
            $start_default = $node->event['start_orig'];
            $end_default = $node->event['end_orig'];
          }
          else {
            $start_default = _event_user_time();
            $start_default = $start_default['year'] . '-' . $start_default['month'] . '-' . $start_default['day'] . ' ' . $start_default['hour'] . ':' . $start_default['minute'];
            $end_default = $start_default;
          }
          $form['event']['event_start'] = array(
            '#title' => t('Start date'),
            '#type' => 'textfield',
            '#default_value' => $start_default,
            '#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['event']['event_end'] = array(
            '#title' => t('End Date'),
            '#type' => 'textfield',
            '#default_value' => $end_default,
            '#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' => -13,
            '#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(isset($node->event['start_orig']) ? $node->event['start_orig'] : _event_user_time(), 'start', $node->event['start_offset']);
          $form['event']['end'] = array(
            '#type' => 'fieldset',
            '#title' => t('End date'),
            '#weight' => -13,
          );
          $form['event']['end']['date'] = event_form_date(isset($node->event['end_orig']) ? $node->event['end_orig'] : _event_user_time(), 'end', $node->event['end_offset']);
        }
        if (variable_get('event_timezone_input', 'site') == 'input') {
          $form['event']['timezone'] = array(
            '#type' => 'select',
            '#title' => t('Time zone'),
            '#default_value' => $node->event['timezone'] ? $node->event['timezone'] : variable_get('date_default_timezone_id', 0),
            '#options' => event_zonelist(),
            '#description' => t('Select the time zone this event occurs in.'),
            '#weight' => -12,
          );
        }
        elseif (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone) && variable_get('event_timezone_input', 'site') == 'user') {
          $form['event']['timezone'] = array(
            '#type' => 'hidden',
            '#value' => $user->timezone_id,
          );
        }
        else {
          $form['event']['timezone'] = array(
            '#type' => 'hidden',
            '#value' => variable_get('date_default_timezone_id', 0),
          );
        }
        if (isset($form['#validate'])) {
          $form['#validate'] = array(
            'event_form_validate' => array(),
          ) + $form['#validate'];
        }
      }
      break;
    case 'system_date_time_settings':
      $zones = event_zonelist('offset');
      $form['date_default_timezone'] = array(
        '#type' => 'select',
        '#title' => t('Default time zone'),
        '#default_value' => variable_get('date_default_timezone_id', 0) . '|' . variable_get('date_default_timezone', 0),
        '#options' => $zones,
        '#description' => t('Select the default site time zone.'),
      );
      $submit['event_extra_setting_form_submit'] = array();
      $form['#submit'] = $form['#submit'] + $submit;
      break;
    case 'user_edit':
      if (variable_get('configurable_timezones', 1) && !arg(3)) {
        $account = user_load(array(
          'uid' => arg(1),
        ));
        $zones = event_zonelist('offset');
        $form['timezone']['timezone'] = array(
          '#type' => 'select',
          '#title' => t('Time zone'),
          '#default_value' => strlen($account->timezone) ? $account->timezone_id . '|' . $account->timezone : variable_get('date_default_timezone_id', 0) . '|' . variable_get('date_default_timezone', 0),
          '#options' => $zones,
          '#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.'),
        );
        $submit['event_extra_user_form_submit'] = array();
        $form['#submit'] = $form['#submit'] + $submit;
      }
  }
}