You are here

function field_schema_field_type_map_alter in Schema 7

Implements hook_schema_field_type_map_alter() on behalf of field.module.

File

./schema.module, line 620
The Schema module provides functionality built on the Schema API.

Code

function field_schema_field_type_map_alter(array &$map, DatabaseSchema $schema, DatabaseConnection $connection) {
  $db_type = $connection
    ->databaseType() . '_type';

  // Load all fields in order to inspect each field's schema.
  $include_additional = array(
    'include_deleted' => TRUE,
    'include_inactive' => TRUE,
  );
  $fields = field_read_fields(array(), $include_additional);
  foreach ($fields as $field) {
    $cols = $field['columns'];

    // Loop through each field column and add any missing mappings.
    foreach ($cols as $col) {
      if (!isset($col['type'])) {
        continue;
      }
      $size = isset($col['size']) ? $col['size'] : 'normal';
      $generic_type = $col['type'] . ':' . $size;
      if (!isset($map[$generic_type])) {

        // Use engine specific type if it exists.
        $map[$generic_type] = isset($col[$db_type]) ? $col[$db_type] : $col['type'];
        $map[$generic_type] = drupal_strtoupper($map[$generic_type]);
      }
    }
  }
}