[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/date/date/ -> date_admin.inc (source)

   1  <?php
   2  //$Id: date_admin.inc,v 1.40.2.3.2.43 2010/12/28 16:37:37 karens Exp $
   3  /**
   4   * @file
   5   * Date administration code.
   6   * Moved to separate file since there is a lot of code here that is not needed often.
   7   */
   8  /**
   9   * Implementation of hook_widget_settings().
  10   */
  11  function _date_widget_settings($op, &$field) {
  12    switch ($op) {
  13      case 'callbacks':
  14        return array('default value' => CONTENT_CALLBACK_CUSTOM);
  15      case 'form':
  16        return date_widget_settings_form($field);
  17  
  18      case 'save':
  19        return array('default_value', 'default_value_code', 'default_value2', 'default_value_code2', 'input_format', 'input_format_custom', 'increment', 'text_parts', 'year_range', 'label_position');
  20  
  21      case 'validate':
  22        if ($field['default_value'] == 'strtotime') {
  23          $is_strtotime = @strtotime($field['default_value_code']);
  24          if (!$is_strtotime) {
  25            form_set_error('default_value_code', t('The Strtotime default value is invalid.'));
  26          }
  27        }
  28        if ($field['default_value2'] == 'strtotime') {
  29          $is_strtotime = @strtotime($field['default_value_code2']);
  30          if (!$is_strtotime) {
  31            form_set_error('default_value_code2', t('The Strtotime default value for the To Date is invalid.'));
  32          }
  33        }
  34        if (in_array($field['widget']['type'], array('date_select', 'date_popup', 'date_select_repeat', 'date_popup_repeat')) && !date_range_valid($field['year_range'])) {
  35          form_set_error('year_range', t('Years back and forward must be in the format -9:+9.'));
  36        }
  37        break;
  38    }
  39  }
  40  
  41  /**
  42   * Custom widget settings manipulation.
  43   *
  44   * CCK widget settings can't use form_set_value(),
  45   * so do it in a custom function.
  46   */
  47  function date_widget_settings_validate(&$form, &$form_state) {
  48    // TODO Not sure there is any limitation any more in this version. Need to check.  
  49    if ($form_state['values']['widget_type'] == 'date_popup') {
  50      // Only a limited set of formats is available for the Date Popup module
  51      if (!empty($form_state['values']['input_format_custom']) || !in_array($form_state['values']['input_format'], date_popup_formats())) {
  52        form_set_value($form['input_format_custom'], NULL, $form_state);
  53        form_set_value($form['input_format'], DATE_FORMAT_DATETIME, $form_state);
  54      }
  55    }
  56    if (isset($form_state['values']['advanced']['label_position'])) {
  57      form_set_value($form['label_position'], $form_state['values']['advanced']['label_position'], $form_state);
  58    }
  59    // Munge the table display for text parts back into an array of text parts.
  60    if (is_array($form_state['values']['advanced']['text_parts'])) {
  61      form_set_value($form['text_parts'], array_keys(array_filter($form_state['values']['advanced']['text_parts'])), $form_state);
  62    }
  63  }
  64  
  65  function date_widget_settings_form($widget) {
  66    $form = array(
  67      '#element_validate' => array('date_widget_settings_validate'),
  68      );
  69    $form['input']['default_value'] = array(
  70      '#type' => 'select', '#title' => t('Default value'),
  71      '#default_value' => !empty($widget['default_value']) ? $widget['default_value'] : 'blank',
  72      '#options' => array('blank' => t('Blank'), 'now' => t('Now'), 'strtotime' => t('Relative')),
  73      '#description' => t("A default value to use for this field. If you select 'Relative', add details below."),
  74      );
  75    $form['input']['default_value2'] = array(
  76      '#type' => 'select', '#title' => t('Default value for To date'),
  77      '#default_value' => !empty($widget['default_value2']) ? $widget['default_value2'] : 'same',
  78      '#options' => array('same' => t('Same as From date'), 'blank' => t('Blank'), 'now' => t('Now'), 'strtotime' => t('Relative')),
  79      '#description' => t("A default value to use for this field. If you select 'Relative', add details below."),
  80      );
  81    $form['input']['default'] = array(
  82      '#type' => 'fieldset',
  83      '#title' => t('Customize Default Value'),
  84      '#description' => '<p>' . t("The custom value for a Relative default should be something that describes a time by reference to the current day using strtotime, like '+90 days' (90 days from the day the field is created) or '+1 Saturday' (the next Saturday). See !strtotime for more details.", array('!strtotime' => l(t('strtotime'), 'http://www.php.net/manual/en/function.strtotime.php'))) . '</p>',
  85      '#collapsible' => TRUE,
  86      '#collapsed' => TRUE,
  87      );
  88    $form['input']['default']['default_value_code'] = array(
  89      '#type' => 'textfield', '#title' => t('Custom value for From date'),
  90      '#default_value' => isset($widget['default_value_code']) ? $widget['default_value_code'] : '',
  91      );
  92  
  93    $form['input']['default']['default_value_code2'] = array(
  94      '#type' => 'textfield', '#title' => t('Custom value for To date'),
  95      '#default_value' => !empty($widget['default_value_code2']) ? $widget['default_value_code2'] : '',
  96      );
  97  
  98    $options = array();
  99    if ($widget['type'] == 'date_popup' && module_exists('date_popup')) {
 100      $formats = date_popup_formats();
 101      $default_format = array_shift($formats);
 102    }
 103    else {
 104      // example input formats must show all possible date parts, so add seconds.
 105      $formats = str_replace('i', 'i:s', array_keys(date_get_formats('short')));
 106      $formats = drupal_map_assoc($formats);
 107      $default_format = str_replace('i', 'i:s', variable_get('date_format_short', 'm/d/Y - H:i'));
 108    }
 109    $now = date_example_date();
 110    foreach ($formats as $f) {
 111      $options[$f] = date_format_date($now, 'custom', $f);
 112    }
 113    $form['input']['input_format'] = array(
 114      '#type' => 'select', '#title' => t('Input format'),
 115      '#default_value' => !empty($widget['input_format']) ? $widget['input_format'] : $default_format,
 116      '#options' => $options,
 117      '#description' => t('Set the order and format for the date parts in the input form. The format will be adapted to remove values not in the granularity for this field.'),
 118    );
 119    
 120    // Only a limited set of formats is available for the Date Popup module
 121    if ($widget['type'] != 'date_popup') {
 122      $form['input']['format']['input_format_custom'] = array(
 123        '#type' => 'textfield',  '#title' => t('Custom input format'),
 124        '#default_value' => !empty($widget['input_format_custom']) ? $widget['input_format_custom'] : '',
 125        '#description' => t("The custom format, if provided, will override the input format selected above. The custom format, if provided, will override the selected display or input options. Define a php date format string like 'm-d-Y H:i' (see <a href=\"@link\">http://php.net/date</a> for more details).", array('@link' => 'http://php.net/date')),
 126      );
 127    }
 128    else {
 129      $form['input']['format']['input_format_custom'] = array(
 130        '#type' => 'hidden',
 131        '#value' => '',
 132        );
 133    }
 134    if (in_array($widget['type'], array('date_select', 'date_popup', 'date_select_repeat', 'date_popup_repeat'))) {
 135      $form['input']['year_range'] = array(
 136        '#type' => 'textfield',
 137        '#title' => t('Years back and forward'),
 138        '#default_value' => !empty($widget['year_range']) ? $widget['year_range'] : '-3:+3',
 139        '#size' => 10,
 140        '#maxsize' => 10,
 141        '#description' => t('Number of years to go back and forward in the year selection list, default is -3:+3.'),
 142        );
 143      $form['input']['increment'] = array(
 144        '#type' => 'select', '#title' => t('Time increment'),
 145        '#default_value' => isset($widget['increment']) ? $widget['increment'] : 1,
 146        '#options' => array(1 => 1, 5 => 5, 10 => 10, 15 => 15, 30 => 30),
 147        '#description' => t('Increment the minute and second fields by this amount.'),
 148      );
 149    }
 150    else {
 151      $form['increment'] = array(
 152        '#type' => 'hidden',
 153        '#value' => !empty($widget['increment']) ? $widget['increment'] : 1,
 154        );
 155      $form['year_range'] = array(
 156        '#type' => 'hidden',
 157        '#value' => isset($widget['year_range']) ? $widget['year_range'] : '-3:+3',
 158        );
 159    }
 160  
 161    $form['label_position'] = array(
 162      '#type' => 'value',
 163      '#value' => !empty($widget['label_position']) ? $widget['label_position'] : 'above',
 164      );
 165    $form['text_parts'] = array(
 166      '#type' => 'value',
 167      '#value' => isset($widget['text_parts']) ? $widget['text_parts'] : '',
 168      );
 169    $form['input']['advanced'] = array(
 170      '#tree' => TRUE,
 171      '#type' => 'fieldset',
 172      '#title' => t('Customize Date Parts'),
 173      '#collapsible' => TRUE,
 174      '#collapsed' => TRUE,
 175      );
 176    $form['input']['advanced']['label_position'] = array(
 177      '#type' => 'radios',
 178      '#options' => array('above' => t('Above'), 'within' => t('Within'), 'none' => t('None')),
 179      '#default_value' => !empty($widget['label_position']) ? $widget['label_position'] : 'above',
 180      '#title' => t('Position of date part labels'),
 181      '#description' => t("The location of date part labels, like 'Year', 'Month', or 'Day'. 'Above' will display them as titles above each date part. 'Within' will insert the label as the first option in the select list and in blank textfields. 'None' will not label any of the date parts. The exact text in the label is controlled by themes like 'date_part_label_year' and 'date_part_label_month'."),
 182      );
 183    $form['input']['advanced']['text_parts'] = array(
 184      '#theme' => $widget['type'] == 'date_select' ? 'date_text_parts' : '',
 185      );
 186    $text_parts = isset($widget['text_parts']) ? (array) $widget['text_parts'] : array();
 187    foreach (date_granularity_names() as $key => $value) {
 188      if ($widget['type'] == 'date_select') {
 189        $form['input']['advanced']['text_parts'][$key] = array(
 190          '#type' => 'radios',
 191          '#default_value' => in_array($key, $text_parts) ? 1 : 0,
 192          '#options' => array(0 => '', 1 => ''),
 193          );
 194      }
 195      else {
 196        $form['input']['advanced']['text_parts'][$key] = array(
 197          '#type' => 'hidden',
 198          '#value' => in_array($key, (array) $widget['text_parts']) ? 1 : 0,
 199          );
 200      }
 201    }
 202    return $form;
 203  }
 204  
 205  /**
 206   * Display the text/select options for date parts in a table
 207   * for easier readability.
 208   */
 209  function theme_date_text_parts($element) {
 210    $names = date_granularity_names();
 211    $rows = array();
 212    foreach ($names as $key => $part) {
 213      if ($element[$key]['#type'] == 'hidden') {
 214        $rows[] = drupal_render($element[$key]);
 215      }
 216      else {
 217        $rows[] = array($names[$key], drupal_render($element[$key][0]), drupal_render($element[$key][1]));
 218      }
 219    }
 220    if ($element['year']['#type'] == 'hidden') {
 221      return implode($rows);
 222    }
 223    else {
 224      $header = array(t('Input Type'), t('Select list'), t('Text field'));
 225      return theme('table', $header, $rows);
 226    }
 227  }
 228  
 229  /**
 230   * Implementation of hook_field_settings().
 231   */
 232  function _date_field_settings($op, $field) {
 233    switch ($op) {
 234      case 'form':
 235        return date_field_settings_form($field);
 236  
 237      case 'validate':
 238        if (!in_array('year', $field['granularity'])) {
 239          form_set_error('granularity', t('Granularity must include a year.'));
 240        }
 241        if ($field['tz_handling'] != 'none' && !in_array('hour', array_filter($field['granularity']))) {
 242          form_set_error('tz_handling', t('Dates without hours granularity must not use any timezone handling.'));
 243        }
 244        break;
 245  
 246      case 'save':
 247  
 248        $options = array('granularity', 'timezone_db', 'tz_handling', 'todate', 'repeat', 'repeat_collapsed', 'default_format');
 249        return $options;
 250  
 251      case 'database columns':
 252        return date_columns($field);
 253  
 254      case 'views data':
 255        $data = content_views_field_views_data($field);
 256        $db_info = content_database_info($field);
 257        $table_alias = content_views_tablename($field);
 258        
 259        // Swap in the date multiple value handler for 
 260        // CCK's regular multiple value handler.
 261        $data[$table_alias][$field['field_name'] .'_value']['field']['handler'] = 'date_handler_field_multiple';
 262        
 263        // Unset the filter and argument handlers, dates can use the generic 
 264        // date argument and filter handlers created by the Date API.
 265        //unset($data[$table_alias][$field['field_name'] .'_value']['argument']);
 266        //unset($data[$table_alias][$field['field_name'] .'_value']['filter']);
 267        $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'date_api_argument_handler';
 268        $data[$table_alias][$field['field_name'] .'_value']['filter']['handler'] = 'date_api_filter_handler';
 269       
 270        // Add in another set of fields for the To date.
 271        if (!empty($field['todate'])) {
 272          $data[$table_alias][$field['field_name'] .'_value']['field']['title'] = $data[$table_alias][$field['field_name'] .'_value']['title'];
 273          $data[$table_alias][$field['field_name'] .'_value']['field']['title short'] = $data[$table_alias][$field['field_name'] .'_value']['title short'];
 274  
 275          $data[$table_alias][$field['field_name'] .'_value2'] = $data[$table_alias][$field['field_name'] .'_value'];
 276  
 277          $data[$table_alias][$field['field_name'] .'_value']['title'] .= ' - ' . t('From date');
 278          $data[$table_alias][$field['field_name'] .'_value']['title short'] .= ' - ' . t('From date');
 279          $data[$table_alias][$field['field_name'] .'_value']['field']['title'] .= ' - ' . t('From date');
 280          $data[$table_alias][$field['field_name'] .'_value']['field']['title short'] .= ' - ' . t('From date');
 281          
 282          $data[$table_alias][$field['field_name'] .'_value2']['title'] .= ' - ' . t('To date');
 283          $data[$table_alias][$field['field_name'] .'_value2']['title short'] .= ' - ' . t('To date');
 284          $data[$table_alias][$field['field_name'] .'_value2']['field']['title'] .= ' - ' . t('To date');
 285          $data[$table_alias][$field['field_name'] .'_value2']['field']['title short'] .= ' - ' . t('To date');
 286  
 287          $data[$table_alias][$field['field_name'] .'_value2']['field']['field'] .= '2';
 288          $data[$table_alias][$field['field_name'] .'_value2']['sort']['field'] .= '2';
 289        }
 290        return $data;
 291    }
 292  }
 293  
 294  /**
 295   *  Callback for field columns.
 296   */
 297  function date_columns($field) {
 298    if ($field['type'] == 'date') {
 299      $db_columns['value'] = array('type' => 'varchar', 'length' => 20, 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE);
 300    }
 301    elseif ($field['type'] == 'datestamp') {
 302      $db_columns['value'] = array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE);
 303    }
 304    elseif ($field['type'] == 'datetime') {
 305      $db_columns['value'] = array('type' => 'datetime', 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE);
 306    }
 307    // If a second date is needed for 'To date', just make a copy of the first one.
 308    if (!empty($field['todate'])) {
 309      $db_columns['value2'] = $db_columns['value'];
 310      
 311      // We don't want CCK to create additional columns, just the first.
 312      // We modify them our own way in views data.
 313      $db_columns['value2']['views'] = FALSE;
 314    }
 315    // timezone and offset columns are used only if date-specific dates are chosen.
 316    if (isset($field['tz_handling']) && $field['tz_handling'] == 'date') {
 317      $db_columns['timezone'] = array('type' => 'varchar', 'length' => 50, 'not null' => FALSE, 'sortable' => TRUE, 'views' => FALSE);
 318      $db_columns['offset'] = array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE, 'views' => FALSE);
 319      if (!empty($field['todate'])) $db_columns['offset2'] = array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE, 'views' => FALSE);
 320    }
 321    if (isset($field['repeat']) && $field['repeat'] == 1) {
 322      $db_columns['rrule'] = array('type' => 'text', 'not null' => FALSE, 'sortable' => FALSE, 'views' => FALSE);
 323    }
 324    return $db_columns;
 325  }
 326  
 327  function date_field_settings_form($field) {
 328    $form = array(
 329      '#element_validate' => array('date_field_settings_validate'),
 330    );
 331    // Make sure granularity is in the right format and has no empty values.
 332    if (!empty($field['granularity']) && is_array($field['granularity'])) {
 333      $granularity = array_filter($field['granularity']);  
 334    }
 335    else {
 336      $granularity = array('year', 'month', 'day', 'hour', 'minute');
 337    }
 338    $tz_handling = isset($field['tz_handling']) ? $field['tz_handling'] : (date_has_time($granularity) ? 'site' : 'none');
 339    
 340    // If adding a repeat, override the Content module's handling of the multiple values option.
 341    if (module_exists('date_repeat') && date_is_repeat_field($field)) {
 342      $form['multiple'] = array('#type' => 'hidden', '#value' => 1);
 343      $form['repeat'] = array('#type' => 'hidden', '#value' => 1);
 344    }
 345    else {
 346      $form['repeat'] = array('#type' => 'hidden', '#value' => 0);
 347    }
 348  
 349    $description = t("Display a matching second date field as a 'To date'. If marked 'Optional' field will be presented but not required. If marked 'Required' the 'To date' will be required if the 'From date' is required or filled in.");
 350    $description .= date_data_loss_warning('To date');
 351    $form['input']['todate'] = array(
 352      '#type' => 'radios', '#title' => t('To Date'),
 353      '#options' => array('' => t('Never'), 'optional' => t('Optional'), 'required' => t('Required')),
 354      '#description' => $description,
 355      '#default_value' => isset($field['todate']) ? $field['todate'] : '',
 356      );
 357    $form['input']['granularity'] = array(
 358      '#type' => 'select', '#title' => t('Granularity'),
 359      '#default_value' => $granularity,
 360      '#options' => date_granularity_names(),
 361      '#multiple' => TRUE,
 362      '#description' => t('Set the date elements to be stored (at least a year is required).'),
 363      );
 364    $format_types = array();  
 365    foreach (date_get_format_types('', TRUE) as $name => $info) {
 366      $format_types[$name] = $info['title'];
 367    }
 368    $form['default_format'] = array(
 369      '#type' => 'select', 
 370      '#title' => t('Default Display'),
 371      '#default_value' => !empty($field['default_format']) ? $field['default_format'] : 'medium',
 372      '#options' => $format_types,
 373      '#description' => t('Select a default format type to be used for the date display. Visit the <a href="@date-time-page">Date and time date format page</a> to add and edit format types.', array('@date-time-page' => url('admin/settings/date-time/formats'))),
 374      );
 375  
 376    $description = t('Select the timezone handling method to be used for this date field.');
 377    $description .= date_data_loss_warning('Time zone handling');
 378    $form['tz_handling'] = array(
 379      '#type' => 'select',
 380      '#title' => t('Time zone handling'),
 381      '#default_value' => $tz_handling,
 382      '#options' => date_timezone_handling_options(),
 383      '#description' => $description,
 384    );
 385    // Force this value to hidden because we don't want to allow it to be changed right now,
 386    // but allow it to be a variable if needed.
 387    $form['timezone_db'] = array(
 388      '#type' => 'hidden',
 389      '#value' => date_get_timezone_db($tz_handling),
 390      );
 391    
 392    if (module_exists('date_repeat') && date_is_repeat_field($field)) {
 393      $form['repeat_collapsed'] = array(
 394        '#type' => 'radios',
 395        '#default_value' => !empty($field['repeat_collapsed']) ? intval($field['repeat_collapsed']) : 0,
 396        '#options' => array(0 => t('Expanded'), 1 => t('Collapsed')),
 397        '#title' => t('Repeat display'),
 398        '#description' => t("Should the repeat options form start out expanded or collapsed? Set to 'Collapsed' to make those options less obtrusive."),
 399        );
 400    }
 401  
 402    return $form;
 403  }
 404  
 405  /**
 406   * Custom field settings manipulation.
 407   *
 408   * CCK field settings can't use form_set_value(),
 409   * so do it in a custom function.
 410   */
 411  function date_field_settings_validate(&$form, &$form_state) {
 412    if ($form_state['values']['tz_handling'] == 'none') {
 413      form_set_value($form['timezone_db'], '', $form_state);
 414    }
 415    else {
 416      form_set_value($form['timezone_db'], date_get_timezone_db($form_state['values']['tz_handling']), $form_state);
 417    }
 418  }
 419  
 420  function date_data_loss_warning($name) {
 421    return '<p class="error">' . t('Changing the %name setting after data has been created could result in the loss of data!', array('%name' => $name)) . '</p>';
 422  }
 423  
 424  /**
 425   *  Timezone handling options
 426   *
 427   *  the 'none' option will do no timezone conversions and will store and display dates exactly as entered
 428   *  useful in locales or situations where timezone conversions are not working reliably,
 429   *  for dates with no times, for historical dates where timezones are irrelevant,
 430   *  or anytime conversion is unnecessary or undesirable
 431   */
 432  function date_timezone_handling_options() {
 433    return array(
 434      'site' => t("Site's time zone"),
 435      'date' => t("Date's time zone"),
 436      'user' => t("User's time zone"),
 437      'utc' => 'UTC',
 438      'none' => t('No time zone conversion'),
 439      );
 440  }
 441  
 442  /**
 443   * Get an example date and make sure the difference between
 444   * month and day and 12 and 24 hours will be clear.
 445   */
 446  function date_example_date() {
 447    $now = date_now();
 448    if (date_format($now, 'm') == date_format($now, 'd')) {
 449      date_modify($now, '+1 day');
 450    }
 451    if (date_format($now, 'H') == date_format($now, 'h')) {
 452      date_modify($now, '+12 hours');
 453    }
 454    return $now;
 455  }
 456  
 457  /**
 458   * Helper function to create a field array with default values for a date 
 459   * $field, based on field type, widget type, and timezone handling.
 460   * 
 461   * This function can be used to make it easier to create new date fields
 462   * in profiles or custom code.
 463   * 
 464   * @param $field_type
 465   *   Can be 'date', 'datestamp', or 'datetime'.
 466   * @param $widget_type
 467   *   Can be 'date_text', 'date_text_repeat', 'date_select', 
 468   *   'date_select_repeat', 'date_popup', 'date_popup_repeat'.
 469   * @param $tz_handling
 470   *   Can be 'site', 'date', 'utc', 'none', or 'user'.
 471   * @param $overrides
 472   *   An optional array of field/widget values that should 
 473   *   override the normal defaults.
 474   */
 475  function date_field_default_values($field_type, $widget_type, $tz_handling, $overrides = array()) {
 476    module_load_include('inc', 'content', 'includes/content.crud');
 477    $repeat_widgets = array('date_select_repeat', 'date_text_repeat', 'date_popup_repeat');
 478    
 479    $base_field_values = array (
 480      'field_name' => '',
 481      'type_name' => '',
 482      'multiple' => in_array($widget_type, $repeat_widgets) ? 1 : 0,
 483      'module' => 'date',
 484      'granularity' => array (
 485        'year' => 'year',
 486        'month' => 'month',
 487        'day' => 'day',
 488        'hour' => 'hour',
 489        'minute' => 'minute',
 490        ),
 491      'timezone_db' => date_get_timezone_db($tz_handling),
 492      'tz_handling' => $tz_handling,
 493      'todate' => 'optional',
 494      'repeat' => in_array($widget_type, $repeat_widgets) ? 1 : 0,
 495      'repeat_collapsed' => 0, 
 496      'default_format' => 'medium',
 497      );
 498    $base_widget_values = array (
 499      'label' => '',
 500      'default_value' => 'now',
 501      'default_value_code' => '', 
 502      'default_value2' => 'same',
 503      'default_value_code2' => '', 
 504      'input_format' => date_default_format($widget_type),
 505      'input_format_custom' => '', 
 506      'increment' => 1,
 507      'text_parts' => array (),
 508      'year_range' => '-3:+3',
 509      'label_position' => 'above',
 510      'weight' => 0,
 511      'description' => '',
 512      'module' => 'date',
 513    );
 514    $field_values['date'] = $base_field_values;
 515    $field_values['date']['type'] = 'date';
 516    
 517    $field_values['datestamp'] = $base_field_values;
 518    $field_values['datestamp']['type'] = 'datestamp';
 519  
 520    $field_values['datetime'] = $base_field_values;
 521    $field_values['datetime']['type'] = 'datetime';
 522  
 523    $widget_values['date_select'] = $base_widget_values;
 524    $widget_values['date_select']['type'] = 'date_select';
 525    
 526    $widget_values['date_text'] = $base_widget_values;
 527    $widget_values['date_text']['type'] = 'date_text';
 528    
 529    $widget_values['date_popup'] = $base_widget_values;
 530    $widget_values['date_popup']['type'] = 'date_popup';
 531    $widget_values['date_popup']['module'] = 'date_popup';
 532      
 533    $widget_values['date_select_repeat'] = $base_widget_values;
 534    $widget_values['date_select_repeat']['type'] = 'date_select_repeat';
 535    
 536    $widget_values['date_text_repeat'] = $base_widget_values;
 537    $widget_values['date_text_repeat']['type'] = 'date_text_repeat';
 538    
 539    $widget_values['date_popup_repeat'] = $base_widget_values;
 540    $widget_values['date_popup_repeat']['type'] = 'date_popup_repeat';
 541    
 542    // Get the basic field array with content module default values.
 543    $field = content_field_default_values($field_type);
 544    
 545    // Update it with default values for this date field and widget type.
 546    foreach ($field_values[$field_type] as $key => $value) {
 547      $field[$key] = $value;
 548    }
 549    foreach ($widget_values[$widget_type] as $key => $value) {
 550      $field['widget'][$key] = $value;
 551    }
 552    
 553    // Allow overrides of specific default values. 
 554    foreach ($overrides as $key => $value) {
 555      if ($key != 'widget') {
 556        $field[$key] = $value;
 557      }
 558      else {
 559        foreach ($value as $widget_key => $widget_value) {
 560          $field['widget'][$widget_key] = $widget_value;
 561        }
 562      }
 563    }
 564    // Make sure multiple gets set correctly for repeating dates.
 565    if ($field['repeat']) $field['multiple'] = 1;
 566    
 567    // Reset columns and db_storage, which may need to be 
 568    // adjusted to the new values.
 569    $field['columns'] = date_columns($field);
 570    $field['db_storage'] = content_storage_type($field);
 571    
 572    return $field;
 573  }
 574  
 575  /**
 576   * Formatter settings.
 577   * 
 578   * Form element used both in the date_handler_field_multiple Views handler
 579   * and on the CCK Display fields page.
 580   */
 581  function _date_formatter_settings($form_state = NULL, $field, $options = array(), $views_form = FALSE) {
 582    $field_name = $field['field_name'];
 583    $field = content_fields($field_name);
 584    $type_name = isset($options['type_name']) ? $options['type_name'] : $field['type_name'];
 585    $context = isset($options['context']) ? $options['context'] : 'full';
 586    if (empty($options['fromto'])) {
 587      $options = date_formatter_get_settings($field_name, $type_name, $context);
 588    }
 589    
 590    $form = array();
 591    $form['fromto'] = array(
 592      '#access' => $field['todate'],
 593      '#weight' => 5,
 594      );
 595    if (isset($options['fromto']) && isset($options['fromto']['fromto'])) {
 596      $default = $options['fromto']['fromto'];
 597    }
 598    else {
 599      $default = 'both';
 600    }
 601    $form['fromto']['fromto'] = array(
 602      '#type' => 'select',
 603      '#options' => array(
 604        'both' => t('Display From and To dates'), 
 605        'value' => t('Display From date only'), 
 606        'value2' => t('Display To date only'),
 607        ),
 608      '#default_value' => $default,
 609      '#weight' => 1,
 610    );  
 611  
 612    $form['multiple'] = array(
 613      '#access' => $field['multiple'],
 614      '#weight' => 6,
 615    );
 616  
 617    // Make the string translatable by keeping it as a whole rather than
 618    // translating prefix and suffix separately.
 619    if (isset($options['multiple']) && isset($options['multiple']['multiple_number'])) {
 620      $default = $options['multiple']['multiple_number'];    
 621    }
 622    else {
 623      $default = '';
 624    }
 625    list($prefix, $suffix) = explode('@count', t('Show @count value(s)'));
 626    $form['multiple']['multiple_number'] = array(
 627      '#type' => 'textfield',
 628      '#size' => 5,
 629      '#field_prefix' => theme('advanced_help_topic', 'date_api', 'date-display') . $prefix,
 630      '#field_suffix' => $suffix,
 631      '#default_value' => $default,
 632      '#weight' => 1,
 633    );
 634    if ($views_form) {
 635      $form['multiple']['multiple_number'] += array(
 636        '#process' => array('views_process_dependency'),
 637        '#dependency' => array('edit-options-multiple-group' => array(TRUE)),
 638      );
 639    }
 640    
 641    if (isset($options['multiple']) && isset($options['multiple']['multiple_from'])) {
 642      $default = $options['multiple']['multiple_from'];    
 643    }
 644    else {
 645      $default = '';
 646    }
 647    list($prefix, $suffix) = explode('@count', t('starting from @count'));
 648    $form['multiple']['multiple_from'] = array(
 649      '#type' => 'textfield',
 650      '#size' => 15,
 651      '#field_prefix' => $prefix,
 652      '#field_suffix' => $suffix,
 653      '#default_value' => $default,
 654      '#weight' => 2,
 655    );
 656    if ($views_form) {
 657      $form['multiple']['multiple_from'] += array(
 658        '#process' => array('views_process_dependency'),
 659        '#dependency' => array('edit-options-multiple-group' => array(TRUE)),
 660      );
 661    }
 662  
 663    if (isset($options['multiple']) && isset($options['multiple']['multiple_to'])) {
 664      $default = $options['multiple']['multiple_to'];    
 665    }
 666    else {
 667      $default = '';
 668    }
 669    list($prefix, $suffix) = explode('@count', t('ending on @count'));
 670    $form['multiple']['multiple_to'] = array(
 671      '#type' => 'textfield',
 672      '#size' => 15,
 673      '#field_prefix' => $prefix,
 674      '#field_suffix' => $suffix,
 675      '#default_value' => $default,
 676      '#weight' => 3,
 677    );
 678    if ($views_form) {
 679      $form['multiple']['multiple_to'] += array(
 680        '#process' => array('views_process_dependency'),
 681        '#dependency' => array('edit-options-multiple-group' => array(TRUE)),
 682      );
 683    }
 684    
 685    $form['repeat'] = array(
 686      '#access' => $field['repeat'],
 687      '#weight' => 7,
 688    );
 689    if (isset($options['repeat']) && isset($options['repeat']['show_repeat_rule'])) {
 690      $default = $options['repeat']['show_repeat_rule'];
 691    }
 692    else {
 693      $default = 'show';
 694    }
 695    $form['repeat']['show_repeat_rule'] = array(
 696      '#type' => 'select',
 697      '#options' => array(
 698        'show' => t('Display repeat rule'), 
 699        'hide' => t('Hide repeat rule')),
 700      '#default_value' => $default,
 701    );
 702  
 703    if (!$views_form) {
 704      $form['field'] = array(
 705        '#type' => 'value',
 706        '#value' => $field,
 707        );
 708      $form['type_name'] = array(
 709        '#type' => 'value',
 710        '#value' => $type_name,
 711        );  
 712      $form['context'] = array(
 713        '#type' => 'value',
 714        '#value' => $context,
 715        );  
 716    }
 717    return $form;
 718  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7