function hook_field_schema

×

Error message

User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
cis7 field.api.php hook_field_schema($field)
cle7 field.api.php hook_field_schema($field)
elmsmedia7 field.api.php hook_field_schema($field)
icor7 field.api.php hook_field_schema($field)
meedjum_blog7 field.api.php hook_field_schema($field)
mooc7 field.api.php hook_field_schema($field)

Define the Field API schema for a field structure.

This is invoked when a field is created, in order to obtain the database schema from the module that defines the field's type.

This hook must be defined in the module's .install file 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

16 functions implement hook_field_schema()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

date_field_schema in sites/all/modules/ulmus/date/date.install
Implements hook_field_schema().
email_field_schema in sites/all/modules/ulmus/email/email.install
Implements hook_field_schema().
entityreference_field_schema in sites/all/modules/ulmus/entityreference/entityreference.install
Implements hook_field_schema().
field_collection_field_schema in sites/all/modules/ulmus/field_collection/field_collection.install
Implements hook_field_schema().
field_hidden_field_schema in sites/all/modules/ulmus/field_hidden/field_hidden.install
Implements hook_field_schema().

... See full list

8 invocations of hook_field_schema()
ctools_field_foreign_keys in sites/all/modules/ulmus/ctools/includes/fields.inc
Derive the foreign keys that a field provides.
drupal_get_complete_schema in includes/bootstrap.inc
Gets the whole database schema.
drupal_get_schema_unprocessed in includes/common.inc
Returns the unprocessed and unaltered version of a module's schema.
field_create_field in modules/field/field.crud.inc
Creates a field.
field_read_fields in modules/field/field.crud.inc
Reads in fields that match an array of conditions.

... See full list

File

modules/field/field.api.php, line 233

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'),
      ),
    ),
  );
}