getFieldTypeMap example

if (!isset($field['size'])) {
      $field['size'] = 'normal';
    }

    // Set the correct database-engine specific datatype.     // In case one is already provided, force it to uppercase.     if (isset($field['mysql_type'])) {
      $field['mysql_type'] = mb_strtoupper($field['mysql_type']);
    }
    else {
      $map = $this->getFieldTypeMap();
      $field['mysql_type'] = $map[$field['type'] . ':' . $field['size']];
    }

    if (isset($field['type']) && $field['type'] == 'serial') {
      $field['auto_increment'] = TRUE;
    }

    return $field;
  }

  /** * {@inheritdoc} */
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 uppercase.     if (isset($field['sqlite_type'])) {
      $field['sqlite_type'] = mb_strtoupper($field['sqlite_type']);
    }
    else {
      $map = $this->getFieldTypeMap();
      $field['sqlite_type'] = $map[$field['type'] . ':' . $field['size']];

      // Numeric fields with a specified scale have to be stored as floats.       if ($field['sqlite_type'] === 'NUMERIC' && isset($field['scale'])) {
        $field['sqlite_type'] = 'FLOAT';
      }
    }

    if (isset($field['type']) && $field['type'] == 'serial') {
      $field['auto_increment'] = TRUE;
    }

    

  protected function fieldTypeMap(Connection $connection$type) {
    // Convert everything to lowercase.     $map = array_map('strtolower', $connection->schema()->getFieldTypeMap());
    $map = array_flip($map);

    // The MySql map contains type:size. Remove the size part.     return isset($map[$type]) ? explode(':', $map[$type])[0] : $type;
  }

  /** * Given a database field type, return a Drupal size. * * @param \Drupal\Core\Database\Connection $connection * The database connection to use. * @param string $type * The MySQL field type. * * @return string|null * The Drupal schema field size. */
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 10. 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)) {
        
Home | Imprint | This part of the site doesn't use cookies.