You are here

protected function JsonItemTest::fieldTypeMap in JSON Field 8

Given a database field type, return a Drupal type.

Parameters

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

string $type: The MySQL field type.

Return value

string The Drupal schema field type. If there is no mapping, the original field type is returned.

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

File

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

Class

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

Namespace

Drupal\Tests\json_field\Kernel

Code

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;
}