You are here

function date_field_schema in Date 8

Same name and namespace in other branches
  1. 7.3 date.install \date_field_schema()
  2. 7 date.install \date_field_schema()
  3. 7.2 date.install \date_field_schema()

Implements hook_field_schema().

File

./date.install, line 11
Install, update and uninstall functions for the Date module.

Code

function date_field_schema($field) {
  switch ($field['settings']['todate']) {
    case '':
      $db_columns = array(
        'value' => array(
          'description' => 'The date value',
          'type' => 'varchar',
          'length' => 20,
          'not null' => FALSE,
        ),
        'data' => array(
          'description' => 'A serialized array with more date info.',
          'type' => 'text',
          'not null' => FALSE,
        ),
      );
      $indexes = array(
        'value' => 'value',
      );
      break;
    default:
      $db_columns = array(
        'value' => array(
          'description' => 'The start date value',
          'type' => 'varchar',
          'length' => 20,
          'not null' => FALSE,
        ),
        'value2' => array(
          'description' => 'The end date value',
          'type' => 'varchar',
          'length' => 20,
          'not null' => FALSE,
        ),
        'data' => array(
          'description' => 'A serialized array with more date info.',
          'type' => 'text',
          'not null' => FALSE,
        ),
      );
      $indexes = array(
        'value' => 'value',
        'value2' => 'value2',
      );
      break;
  }

  // If a second date is needed for 'End date', make a copy of the first one.
  // 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['offset'] = array(
      'type' => 'int',
      'not null' => FALSE,
    );
    if (!empty($field['settings']['todate'])) {
      $db_columns['offset2'] = array(
        'type' => 'int',
        'not null' => FALSE,
      );
    }
  }
  return array(
    'columns' => $db_columns,
    'indexes' => $indexes,
  );
}