You are here

function jst_timer_form_alter in Javascript Timer 7

Same name and namespace in other branches
  1. 6 widgets/jst_timer.module \jst_timer_form_alter()

Implementation of hook_form_alter(). Add the timer widget specific settings to admin screen.

File

widgets/jst_timer.module, line 358
Default widget implementation for an up and down timer. This widget does not use hook_ctwidget as it is always included.

Code

function jst_timer_form_alter(&$form, $form_state, $form_id) {

  // Get a list of formats.
  $timer_formats = jst_timer_get_formats();
  switch ($form_id) {

    //change this to form_id of the form you want to alter
    case 'jstimer_admin_settings':
      $form['jst_timer'] = array(
        '#type' => 'fieldset',
        '#title' => t('Timer widget'),
        '#weight' => 1,
      );
      $form['jst_timer']['jst_timer_formats'] = array(
        '#type' => 'fieldset',
        '#title' => t('Timer formats'),
        '#collapsible' => TRUE,
        '#tree' => TRUE,
        '#description' => t("Formats control how each timer will display and also allow you to add styles/classes.") . '<br/>' . t("Available replacement values are: %day%, %month%, %year%, %dow%, %moy%, %years%, %ydays%, %days%, %hours%, %mins%, and %secs%.") . '<br/>' . t("Refresh the page after saving to reload the examples."),
      );
      $i = 0;
      foreach ($timer_formats as $i => $format) {

        // 0 is the global default format.
        if ($i == 0) {
          $form['jst_timer']['jst_timer_formats'][] = array(
            '#type' => 'textarea',
            '#rows' => 1,
            '#title' => t('Global format'),
            '#default_value' => $format,
            '#description' => theme('jstimer', array(
              'widget_name' => 'jst_timer',
              'widget_args' => array(
                'datetime' => '2015-05-02T08:11:00+02:00',
                'format_num' => $i,
              ),
            )),
          );
        }
        else {
          $form['jst_timer']['jst_timer_formats'][] = array(
            '#type' => 'textarea',
            '#rows' => 1,
            '#title' => t('Format preset %preset_num', array(
              '%preset_num' => $i,
            )),
            '#default_value' => $format,
            '#description' => theme('jstimer', array(
              'widget_name' => 'jst_timer',
              'widget_args' => array(
                'datetime' => '2015-05-02T08:11:00+02:00',
                'format_num' => $i,
              ),
            )),
          );
        }
      }

      // Add a blank one.
      $form['jst_timer']['jst_timer_formats'][] = array(
        '#type' => 'textarea',
        '#rows' => 1,
        '#title' => t('Format preset %preset_num', array(
          '%preset_num' => $i + 1,
        )),
        '#default_value' => '',
        '#description' => t('Add a new preset.  After you save, another blank one will be added.'),
      );
      $form['jst_timer']['actions'] = array(
        '#type' => 'fieldset',
        '#title' => t('Timer actions'),
        '#weight' => 1,
        '#description' => t('Javascript actions that execute when a countdown timer completes or nears completion.'),
      );

      // Proximity styling.
      $form['jst_timer']['actions']['proximity'] = array(
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#title' => t('Proximity styling'),
        '#description' => t('Dynamic styling of timer when countdown approaches completion.'),
        '#tree' => FALSE,
      );
      $form['jst_timer']['actions']['proximity']['jstimer_highlight'] = array(
        '#type' => 'textfield',
        '#size' => 100,
        '#title' => t('CSS statement'),
        '#default_value' => variable_get('jstimer_highlight', DEFAULT_HIGHLIGHT),
        '#description' => t("Use a complete css attribute statement like style=\"\" or class=\"\"."),
      );
      $form['jst_timer']['actions']['proximity']['jstimer_highlight_threshold'] = array(
        '#type' => 'textfield',
        '#size' => 5,
        '#title' => t('Threshold (minutes)'),
        '#default_value' => variable_get('jstimer_highlight_threshold', DEFAULT_HIGHLIGHT_THRESHOLD),
        '#description' => t("Number of minutes before css statement is applied."),
      );
      $form['jst_timer']['actions']['proximity']['jstimer_highlight_down'] = array(
        '#type' => 'checkbox',
        '#title' => t('Apply to countdown timers'),
        '#default_value' => variable_get('jstimer_highlight_down', DEFAULT_HIGHLIGHT_DOWN),
      );
      $form['jst_timer']['actions']['proximity']['jstimer_highlight_up'] = array(
        '#type' => 'checkbox',
        '#title' => t('Apply to down/up (NASA) timers'),
        '#default_value' => variable_get('jstimer_highlight_up', DEFAULT_HIGHLIGHT_UP),
        '#description' => t("Styling latches (ie stays on forever after the threshold has been reached)."),
      );
      $form['jst_timer']['actions']['proximity']['jstimer_highlight_threshold'] = array(
        '#type' => 'textfield',
        '#size' => 5,
        '#title' => t('Threshold (minutes)'),
        '#default_value' => variable_get('jstimer_highlight_threshold', DEFAULT_HIGHLIGHT_THRESHOLD),
        '#description' => t("Number of minutes before css statement is applied."),
      );

      // Redirect URL.
      $form['jst_timer']['actions']['redirect'] = array(
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#title' => t('Timer complete redirect'),
        '#description' => t('Javascript redirect/refresh that runs when a countdown completes.'),
        '#tree' => FALSE,
      );
      $form['jst_timer']['actions']['redirect']['jst_timer_redirect_path'] = array(
        '#type' => 'textfield',
        '#size' => 100,
        '#title' => t('Redirect path'),
        '#default_value' => variable_get('jst_timer_redirect_path', ''),
        '#description' => t('An absolute URL or %reload for same page.', array(
          '%reload' => '<reload>',
        )),
      );
      $form['jst_timer']['actions']['redirect']['jst_timer_redirect_delay'] = array(
        '#type' => 'textfield',
        '#size' => 5,
        '#title' => t('Delay (seconds)'),
        '#default_value' => variable_get('jst_timer_redirect_delay', 3),
        '#description' => t("Number of seconds to wait after countdown completion before running redirect/refresh."),
      );

      // Timer complete message.
      $form['jst_timer']['actions']['jst_timer_complete_message'] = array(
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#title' => t('Timer complete message'),
        '#description' => t('Message that replaces timer when a countdown completes.'),
        '#weight' => 1,
      );
      $form['jst_timer']['actions']['jst_timer_complete_message']['jst_timer_complete_message'] = array(
        '#type' => 'textfield',
        '#title' => t('Message'),
        '#size' => 80,
        '#default_value' => variable_get('jst_timer_complete_message', DEFAULT_TIMER_COMPLETE),
      );

      // Timer complete alert.
      $form['jst_timer']['actions']['jst_timer_complete_alert'] = array(
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#title' => t('Timer complete alert message'),
        '#description' => t('Message that pops up in an alert box when when a countdown completes.  Do NOT use HTML.'),
        '#weight' => 1,
      );
      $form['jst_timer']['actions']['jst_timer_complete_alert']['jst_timer_complete_alert_message'] = array(
        '#type' => 'textfield',
        '#title' => t('Message'),
        '#size' => 80,
        '#default_value' => variable_get('jst_timer_complete_alert_message', ''),
      );
      $form['buttons']['#weight'] = 2;

      // Put this module's submit handler first so you can remove elements that
      // this module handles in the submit handler.
      array_unshift($form['#submit'], 'jst_timer_admin_settings_submit');
      break;
  }
}