You are here

function availability_calendars_form_alter in Availability Calendars 6

Same name and namespace in other branches
  1. 5 availability_calendars.module \availability_calendars_form_alter()
  2. 6.2 availability_calendars.module \availability_calendars_form_alter()

Implementation of hook_form_alter(). All form alterations needed for the calendars.

@global object $user

_state

Parameters

array $form:

string $form_id:

File

./availability_calendars.module, line 697
Availability Calendars Module.

Code

function availability_calendars_form_alter(&$form, &$form_state, $form_id) {
  global $user;

  // Alter node type form to allow availability support to be enabled/disabled
  if ($form_id == 'node_type_form') {
    $settings = availability_calendar_getsettings();
    $enabled = $settings->status[$form['#node_type']->type];
    $form['availability_calendars'] = array(
      '#type' => 'fieldset',
      '#title' => t('Availability calendars'),
      '#collapsible' => TRUE,
      '#collapsed' => !$enabled,
    );
    $form['availability_calendars']['availability_calendars_settings_system-type'] = array(
      '#type' => 'checkbox',
      '#title' => t('Availability calendar support'),
      '#default_value' => $enabled,
      '#description' => t('Enable or disable availability support for this content type. If enabled, node owner will be able to specify node availability.'),
    );

    // TODO: add options for status' here
  }
  elseif (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id) {
    $settings = availability_calendar_getsettings('node', $form['nid']['#value']);
    if ($settings->system->status[$form['type']['#value']] === 1) {
      $form['availability_calendars'] = array(
        '#type' => 'fieldset',
        '#title' => t('Availability calendar settings'),
      );
      $form['availability_calendars']['startofweek'] = array(
        '#type' => 'select',
        '#title' => t('First day of week'),
        '#default_value' => $settings->startofweek,
        '#options' => array(
          6 => t('Monday'),
          5 => t('Tuesday'),
          4 => t('Wednesday'),
          3 => t('Thursday'),
          2 => t('Friday'),
          1 => t('Saturday'),
          0 => t('Sunday'),
        ),
      );
      $form['availability_calendars']['defaultstatus'] = array(
        '#type' => 'select',
        '#title' => t('Default status for each day'),
        '#default_value' => $settings->defaultstatus,
        '#options' => availability_calendars_options(),
      );
      if ($settings->system->showteaser === 0) {
        $form['availability_calendars']['showteaser'] = array(
          '#type' => 'checkbox',
          '#title' => t('Show calendars in teaser'),
          '#default_value' => $settings->showteaser,
        );
      }

      // allow users to choose whether a key should be shown on the node on a per node basis
      $form['availability_calendars']['showkey'] = array(
        '#type' => 'checkbox',
        '#title' => t('Show a key for the availability calendars'),
        '#default_value' => $settings->showkey,
      );

      // whether to use only the first letter for the day of the week or not
      $form['availability_calendars']['firstletter'] = array(
        '#type' => 'checkbox',
        '#title' => t('Use only the first letter from the day of the week'),
        '#default_value' => $settings->firstletter,
      );
      if ($settings->system->hideold === 0) {
        $form['availability_calendars']['hideold'] = array(
          '#type' => 'checkbox',
          '#title' => t('Set all calendars to have their past dates shown as fully booked'),
          '#default_value' => $settings->hideold,
        );
      }
    }
  }
}