diff --git a/modules/field/field.api.php b/modules/field/field.api.php index fccf479..807ef54 100644 --- a/modules/field/field.api.php +++ b/modules/field/field.api.php @@ -272,6 +272,17 @@ function hook_field_schema($field) { } /** + * Allows modules to alter the schema for a field. + * + * @param $schema + * The schema definition as returned by hook_field_schema(). + * @param $field + * The field definition. + */ +function hook_field_schema_alter(&$schema, $field) { +} + +/** * Define custom load behavior for this module's field types. * * Unlike most other field hooks, this hook operates on multiple entities. The diff --git a/modules/field/field.crud.inc b/modules/field/field.crud.inc index e34c0c5..5c0f09c 100644 --- a/modules/field/field.crud.inc +++ b/modules/field/field.crud.inc @@ -18,6 +18,23 @@ */ /** + * Retrieves the schema for a field. + * + * @param $field + * The field array to get the schema definition against. + * @return + * The field schema definition array. + */ +function field_retrieve_schema($field) { + module_load_install($field['module']); + $schema = (array) module_invoke($field['module'], 'field_schema', $field); + $schema += array('columns' => array(), 'indexes' => array(), 'foreign keys' => array()); + // Give other modules a chance to alter this definition. + drupal_alter('field_schema', $schema, $field); + return $schema; +} + +/** * Creates a field. * * This function does not bind the field to any bundle; use @@ -126,9 +143,7 @@ function field_create_field($field) { $field['storage']['module'] = $storage_type['module']; $field['storage']['active'] = 1; // Collect storage information. - module_load_install($field['module']); - $schema = (array) module_invoke($field['module'], 'field_schema', $field); - $schema += array('columns' => array(), 'indexes' => array(), 'foreign keys' => array()); + $schema = field_retrieve_schema($field); // 'columns' are hardcoded in the field type. $field['columns'] = $schema['columns']; // 'foreign keys' are hardcoded in the field type. @@ -238,9 +253,7 @@ function field_update_field($field) { // Collect the new storage information, since what is in // $prior_field may no longer be right. - module_load_install($field['module']); - $schema = (array) module_invoke($field['module'], 'field_schema', $field); - $schema += array('columns' => array(), 'indexes' => array()); + $schema = field_retrieve_schema($field); // 'columns' are hardcoded in the field type. $field['columns'] = $schema['columns']; // 'indexes' can be both hardcoded in the field type, and specified in the @@ -365,9 +378,7 @@ function field_read_fields($params = array(), $include_additional = array()) { module_invoke_all('field_read_field', $field); // Populate storage information. - module_load_install($field['module']); - $schema = (array) module_invoke($field['module'], 'field_schema', $field); - $schema += array('columns' => array(), 'indexes' => array()); + $schema = field_retrieve_schema($field); $field['columns'] = $schema['columns']; $field_name = $field['field_name'];