Schema::processField

protected Schema::processField($field)

Set database-engine specific properties for a field.

Parameters

$field: A field description array, as specified in the schema documentation.

File

core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php, line 320

Class

Schema
PostgreSQL implementation of \Drupal\Core\Database\Schema.

Namespace

Drupal\Core\Database\Driver\pgsql

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
protected function processField($field) {
  if (!isset($field['size'])) {
    $field['size'] = 'normal';
  }
 
  // Set the correct database-engine specific datatype.
  // In case one is already provided, force it to lowercase.
  if (isset($field['pgsql_type'])) {
    $field['pgsql_type'] = Unicode::strtolower($field['pgsql_type']);
  }
  else {
    $map = $this->getFieldTypeMap();
    $field['pgsql_type'] = $map[$field['type'] . ':' . $field['size']];
  }
 
  if (!empty($field['unsigned'])) {
    // Unsigned datatypes are not supported in PostgreSQL 9.1. In MySQL,
    // they are used to ensure a positive number is inserted and it also
    // doubles the maximum integer size that can be stored in a field.
    // The PostgreSQL schema in Drupal creates a check constraint
    // to ensure that a value inserted is >= 0. To provide the extra
    // integer capacity, here, we bump up the column field size.
    if (!isset($map)) {
      $map = $this->getFieldTypeMap();
    }
    switch ($field['pgsql_type']) {
      case 'smallint':
        $field['pgsql_type'] = $map['int:medium'];
        break;
      case 'int':
        $field['pgsql_type'] = $map['int:big'];
        break;
    }
  }
  if (isset($field['type']) && $field['type'] == 'serial') {
    unset($field['not null']);
  }
  return $field;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.