function Schema::processField

Same name in this branch
  1. 8.9.x core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php \Drupal\Core\Database\Driver\sqlite\Schema::processField()
  2. 8.9.x core/lib/Drupal/Core/Database/Driver/mysql/Schema.php \Drupal\Core\Database\Driver\mysql\Schema::processField()
Same name in other branches
  1. 9 core/modules/sqlite/src/Driver/Database/sqlite/Schema.php \Drupal\sqlite\Driver\Database\sqlite\Schema::processField()
  2. 9 core/modules/mysql/src/Driver/Database/mysql/Schema.php \Drupal\mysql\Driver\Database\mysql\Schema::processField()
  3. 9 core/modules/pgsql/src/Driver/Database/pgsql/Schema.php \Drupal\pgsql\Driver\Database\pgsql\Schema::processField()
  4. 10 core/modules/sqlite/src/Driver/Database/sqlite/Schema.php \Drupal\sqlite\Driver\Database\sqlite\Schema::processField()
  5. 10 core/modules/mysql/src/Driver/Database/mysql/Schema.php \Drupal\mysql\Driver\Database\mysql\Schema::processField()
  6. 10 core/modules/pgsql/src/Driver/Database/pgsql/Schema.php \Drupal\pgsql\Driver\Database\pgsql\Schema::processField()
  7. 11.x core/modules/sqlite/src/Driver/Database/sqlite/Schema.php \Drupal\sqlite\Driver\Database\sqlite\Schema::processField()
  8. 11.x core/modules/mysql/src/Driver/Database/mysql/Schema.php \Drupal\mysql\Driver\Database\mysql\Schema::processField()
  9. 11.x core/modules/pgsql/src/Driver/Database/pgsql/Schema.php \Drupal\pgsql\Driver\Database\pgsql\Schema::processField()

Set database-engine specific properties for a field.

Parameters

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

3 calls to Schema::processField()
Schema::addField in core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
Add a new field to a table.
Schema::changeField in core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
Change a field definition.
Schema::createTableSql in core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
Generate SQL to create a new table from a Drupal schema definition.

File

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

Class

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

Namespace

Drupal\Core\Database\Driver\pgsql

Code

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'] = mb_strtolower($field['pgsql_type']);
    }
    else {
        $map = $this->getFieldTypeMap();
        $field['pgsql_type'] = $map[$field['type'] . ':' . $field['size']];
    }
    if (!empty($field['unsigned'])) {
        // Unsigned data types 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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.