You are here

function content_table_schema in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 6.3 content.module \content_table_schema()
  2. 6.2 content.module \content_table_schema()

A basic schema used by all field and type tables.

This will only add the columns relevant for the specified field. Leave $field['columns'] empty to get only the base schema, otherwise the function will return the whole thing.

3 calls to content_table_schema()
content_alter_db in includes/content.admin.inc
Perform adds, alters, and drops as needed to synchronize the database with new field definitions.
content_alter_db_analyze in includes/content.admin.inc
Schema Alter Analyze
content_schema in ./content.install
Implementation of hook_schema.

File

./content.module, line 1674
Allows administrators to associate custom fields to content types.

Code

function content_table_schema($field = NULL) {
  $schema = array(
    'fields' => array(
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'vid',
    ),
  );

  // Add delta column if needed.
  if (!empty($field['multiple'])) {
    $schema['fields']['delta'] = array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    );
    $schema['primary key'][] = 'delta';
  }
  $schema['content fields'] = array();

  // Add field columns column if needed.
  // This function is called from install files where it is not safe
  // to use content_fields() or content_database_info(), so we
  // just used the column values stored in the $field.
  // We also need the schema to include fields from disabled modules
  // or there will be no way to delete those fields.
  if (!empty($field['columns'])) {
    foreach ($field['columns'] as $column => $attributes) {
      $column_name = $field['field_name'] . '_' . $column;
      unset($attributes['column']);
      unset($attributes['sortable']);
      $schema['fields'][$column_name] = $attributes;
    }
    $schema['content fields'][] = $field['field_name'];
  }
  return $schema;
}