| 7 field.api.php | hook_field_schema($field) |
| 8 field.api.php | hook_field_schema($field) |
Define the Field API schema for a field structure.
This hook MUST be defined in .install for it to be detected during installation and upgrade.
Parameters
$field: A field structure.
Return value
An associative array with the following keys:
- columns: An array of Schema API column specifications, keyed by column name. This specifies what comprises a value for a given field. For example, a value for a number field is simply 'value', while a value for a formatted text field is the combination of 'value' and 'format'. It is recommended to avoid having the column definitions depend on field settings when possible. No assumptions should be made on how storage engines internally use the original column name to structure their storage.
- indexes: (optional) An array of Schema API indexes definitions. Only columns that appear in the 'columns' array are allowed. Those indexes will be used as default indexes. Callers of field_create_field() can specify additional indexes, or, at their own risk, modify the default indexes specified by the field-type module. Some storage engines might not support indexes.
- foreign keys: (optional) An array of Schema API foreign keys definitions.
Related topics
7 functions implement hook_field_schema()
7 invocations of hook_field_schema()
File
- modules/
field/ field.api.php, line 221
Code
function hook_field_schema($field) {
if ($field['type'] == 'text_long') {
$columns = array(
'value' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
);
}
else {
$columns = array(
'value' => array(
'type' => 'varchar',
'length' => $field['settings']['max_length'],
'not null' => FALSE,
),
);
}
$columns += array(
'format' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
);
return array(
'columns' => $columns,
'indexes' => array(
'format' => array('format'),
),
'foreign keys' => array(
'format' => array(
'table' => 'filter_format',
'columns' => array('format' => 'format'),
),
),
);
}
Login or register to post comments
Comments
Where can we find the FULL LIST
Where can we find the FULL LIST of allowed keys for each column specification?
Schema data structure reference
http://drupal.org/node/146939
How to uninstall fields created via hook_field_schema
It's unclear how to uninstall a schema once it has been installed. If someone know more, please post it here.
Uninstall
On Converting 6.x modules to 7.x - Categorical:
Database schema (un)installed automatically.
I would assume the same applies for this hook, but please correct me if I'm wrong.
is there a hook_field_schema_alter()?
Is there an equivalent of hook_schema_alter() for hook_field_schema()? How does one go about altering a core module field schema (e.g. image module) in contrib space? Guidance would be much appreciated.