You are here

protected function JsonItemTest::fieldSizeMap in JSON Field 8

Given a database field type, return a Drupal size.

Parameters

\Drupal\Core\Database\Connection $connection: The database connection to use.

string $type: The MySQL field type.

Return value

string The Drupal schema field size.

1 call to JsonItemTest::fieldSizeMap()
JsonItemTest::getTableSchema in tests/src/Kernel/JsonItemTest.php

File

tests/src/Kernel/JsonItemTest.php, line 349

Class

JsonItemTest
@coversDefaultClass \Drupal\json_field\Plugin\Field\FieldType\JSONItem

Namespace

Drupal\Tests\json_field\Kernel

Code

protected function fieldSizeMap(Connection $connection, $type) {

  // Convert everything to lowercase.
  $map = array_map('strtolower', $connection
    ->schema()
    ->getFieldTypeMap());
  $map = array_flip($map);
  $schema_type = explode(':', $map[$type])[0];

  // Only specify size on these types.
  if (in_array($schema_type, [
    'blob',
    'float',
    'int',
    'text',
  ])) {

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