1 date.install date_field_schema($field)

Implements hook_field_schema().

File

core/modules/date/date.install, line 10
Install, update and uninstall functions for the Date module.

Code

function date_field_schema($field) {
  $db_columns = array();
  switch ($field['type']) {
    case 'datestamp':
      $db_columns['value'] = array(
        'type' => 'int',
        'not null' => FALSE,
        'sortable' => TRUE,
        'views' => TRUE,
      );
      break;

    case 'datetime':
      $db_columns['value'] = array(
        'type' => 'datetime',
        'mysql_type' => 'datetime',
        'not null' => FALSE,
        'sortable' => TRUE,
        'views' => TRUE,
      );
      break;

    default:
      $db_columns['value'] = array(
        'type' => 'varchar',
        'length' => 20,
        'not null' => FALSE,
        'sortable' => TRUE,
        'views' => TRUE,
      );
      break;
  }

  // If a second date is needed for 'End date', make a copy of the first one.
  if (!empty($field['settings']['todate'])) {
    $db_columns['value2'] = $db_columns['value'];

    // We don't want Field API to create additional columns, just the first.
    // We modify them our own way in views data.
    $db_columns['value2']['views'] = FALSE;
  }
  // Timezone and offset columns are used only if date-specific dates are used.
  if (isset($field['settings']['tz_handling']) && $field['settings']['tz_handling'] == 'date') {
    $db_columns['timezone'] = array(
      'type' => 'varchar',
      'length' => 50,
      'not null' => FALSE,
      'sortable' => TRUE,
      'views' => FALSE,
    );
    $db_columns['offset'] = array(
      'type' => 'int',
      'not null' => FALSE,
      'sortable' => TRUE,
      'views' => FALSE,
    );
    if (!empty($field['settings']['todate'])) {
      $db_columns['offset2'] = array(
        'type' => 'int',
        'not null' => FALSE,
        'sortable' => TRUE,
        'views' => FALSE);
    }
  }
  return array('columns' => $db_columns);
}