By poker10 on
Change record status:
Project:
Introduced in branch:
7.x
Introduced in version:
7.99
Description:

A new hook_field_schema_alter() was added in Drupal 7. See the example implementation:

/**
 * Allow modules to alter the schema for a field.
 *
 * @param array $schema
 * The schema definition as returned by hook_field_schema().
 * @param array $field
 * The field definition.
 *
 * @see field_retrieve_schema()
 */
function hook_field_schema_alter(&$schema, $field) {
 if ($field['type'] == 'image') {
 // Alter the length of a field.
 $schema['columns']['alt']['length'] = 2048;
 // Add an additional column of data.
 $schema['columns']['additional_column'] = array(
 'description' => "Additional column added to image field table.",
 'type' => 'varchar',
 'length' => 128,
 'not null' => FALSE,
 );
 // Add an additional index.
 $schema['indexes']['fid_additional_column'] = array('fid', 'additional_column');
 }
}
Impacts:
Module developers
Site templates, recipes and distribution developers