function content_table_schema in Content Construction Kit (CCK) 6.2
Same name and namespace in other branches
- 6.3 content.module \content_table_schema()
- 6 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 2060 - 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',
),
'indexes' => array(
'nid' => array(
'nid',
),
),
);
// 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;
if (isset($attributes['index']) && $attributes['index']) {
$schema['indexes'][$column_name] = array(
$column_name,
);
unset($attributes['index']);
}
unset($attributes['column']);
unset($attributes['sortable']);
$schema['fields'][$column_name] = $attributes;
}
$schema['content fields'][] = $field['field_name'];
}
return $schema;
}