You are here

public function countdown_box::options_form in Countdown 7.2

Implementation of boxes_box::options_form().

Overrides boxes_box::options_form

File

plugins/countdown_box.inc, line 32

Class

countdown_box
Countdown box.

Code

public function options_form(&$form_state) {
  $form = array();
  $form['countdown_plugin'] = array(
    '#title' => t('Countdown plugin'),
    '#description' => t('The plugin to use for the countdown.'),
    '#type' => 'radios',
    '#default_value' => $this->options['countdown_plugin'],
  );

  // Get the list of countdown plugins.
  // Yes, this is a plugin within a plugin. The alternative would be to have
  // a different box type for each countdown, which seems messier.
  // This way allows the possibility of the countdowns being used
  // independently of boxes.
  $plugins = ctools_get_plugins('countdown', 'countdown');
  $options = array();
  foreach ($plugins as $plugin_info) {
    $options[$plugin_info['name']] = $plugin_info['label'];

    // Add the description to the radio element that doesn't exist yet:
    // FormAPI picks this up when it expands the radios.
    $form['countdown_plugin'][$plugin_info['name']]['#description'] = $plugin_info['description'];
  }
  $form['countdown_plugin']['#options'] = $options;

  // Convert the date and time from UTC.
  // Make a date object from the given time, with the site's default timezone.
  $target_date = new dateObject($this->options['countdown_target'], new DateTimeZone('UTC'));

  // Convert the date to the site timezone.
  $target_date
    ->setTimezone(date_default_timezone_object());
  $form['countdown_target'] = array(
    '#title' => t('Target date'),
    '#description' => t("The date and time the countdown will count towards, in the site's timezone."),
    '#type' => 'date_popup',
    '#date_format' => variable_get('date_format_short', 'm/d/Y - H:i'),
    '#default_value' => $target_date
      ->format(DATE_FORMAT_DATETIME),
    // Get the site timezone.
    '#date_timezone' => date_default_timezone(),
    '#required' => TRUE,
  );

  // Optional elements follow.
  $form['countdown_elements'] = array(
    '#title' => t('Countdown elements'),
    '#description' => t('The date elements to include in the countdown.'),
    '#type' => 'checkboxes',
    // This loses us weeks :( TODO
    '#options' => date_granularity_names(),
    '#default_value' => $this->options['countdown_elements'],
  );
  $form['event_name'] = array(
    '#title' => t('Event name'),
    '#description' => t('The name of the event'),
    '#type' => 'textfield',
    '#default_value' => $this->options['event_name'],
    '#max_length' => 250,
  );
  $form['event_description'] = array(
    '#title' => t('Countdown description'),
    '#description' => t('Enter the description to go below the countdown. You may use <strong>@event_name</strong> as a special token in this field that will be replaced with the dynamic value of the event name. If you do not wish to have a description, simply leave this field blank.'),
    '#type' => 'textfield',
    '#default_value' => $this->options['event_description'],
    '#max_length' => 250,
    '#size' => 80,
    '#required' => FALSE,
  );
  $form['event_url'] = array(
    '#type' => 'textfield',
    '#title' => t('Event URL'),
    '#default_value' => $this->options['event_url'],
    '#maxlength' => 250,
    '#description' => t("A URL for the event. If set, turns the event description into a link to more information about the event."),
    '#required' => FALSE,
  );

  // Add states for the form elements that are optional, so they are hidden
  // when a plugin that does not support them is selected.
  foreach ($plugins as $plugin_info) {
    foreach ($plugin_info['supported_options'] as $supported_key) {
      $form[$supported_key]['#states']['visible'][':input[name="countdown_plugin"]'][] = array(
        'value' => $plugin_info['name'],
      );
    }
  }
  return $form;
}