You are here

function cck_time_widget_settings in CCK Time 5

Implementation of hook_widget_settings().

Parameters

$op: The operation to be performed.

$widget: The widget on which the operation is to be performed.

Return value

This varies depending on the operation.

  • "form": an array of form elements to add to the settings page.
  • "validate": no return value. Use form_set_error().
  • "save": an array of names of form elements to be saved in the database.
  • "callbacks": an array describing the widget's behaviour regarding hook_widget operations. The array is keyed by hook_widget operations ('form', 'validate'...) and has the following possible values : CONTENT_CALLBACK_NONE : do nothing for this operation CONTENT_CALLBACK_CUSTOM : use the behaviour in hook_widget(operation) CONTENT_CALLBACK_DEFAULT : use content.module's default bahaviour Note : currently only the 'default value' operation implements this feature. All other widget operation implemented by the module _will_ be executed no matter what.

File

./cck_time.module, line 179

Code

function cck_time_widget_settings($op, $widget) {
  switch ($op) {
    case 'callbacks':
      return array(
        'default value' => CONTENT_CALLBACK_CUSTOM,
      );
    case 'form':
      $form = array();
      $form['cck_time']['format'] = array(
        '#type' => 'select',
        '#title' => t('Time format'),
        '#default_value' => isset($widget['format']) ? $widget['format'] : 1,
        '#options' => array(
          '24' => '24-hour (24:59)',
          '12' => '12-hour (12:59AM)',
        ),
        '#description' => t('Record times in 24-hour format or in 12-hour format (with AM/PM).'),
      );
      $form['cck_time']['increment'] = array(
        '#type' => 'select',
        '#title' => t('Minute increment'),
        '#default_value' => isset($widget['increment']) ? $widget['increment'] : 1,
        '#options' => array(
          1 => 1,
          5 => 5,
          10 => 10,
          15 => 15,
          30 => 30,
        ),
        '#description' => t('Increment the minute values by this amount.'),
      );
      return $form;
    case 'validate':
      $format_OK = array(
        '12',
        '24',
      );
      $increment_OK = array(
        '1',
        '5',
        '10',
        '15',
        '30',
      );
      if (!in_array($widget['format'], $format_OK) || !in_array($widget['increment'], $increment_OK)) {
        form_set_error('', 'There was a a problem with the time settings. Please check your values.');
      }
      break;
    case 'save':

      //cache_clear_all('date_formats:'. $widget['field_name'] .':'. $widget['type_name'], 'cache');
      return array(
        'increment',
        'format',
      );
  }
}