diff --git a/src/Plugin/Field/FieldType/JSONItem.php b/src/Plugin/Field/FieldType/JSONItem.php index c09661c..3910d10 100644 --- a/src/Plugin/Field/FieldType/JSONItem.php +++ b/src/Plugin/Field/FieldType/JSONItem.php @@ -30,24 +30,24 @@ use Drupal\Core\TypedData\DataDefinition; class JSONItem extends FieldItemBase { /** - * 2^8-1 + * Schema API 255 varchar. */ const SIZE_SMALL = 255; /** - * 2^16-1 + * Schema API normal text 16KB (16*2^10). */ - const SIZE_NORMAL = 65535; + const SIZE_NORMAL = 16384; /** - * 2^24-1 + * Schema API medium text 16MB (16*2^20). */ - const SIZE_MEDIUM = 16777215; + const SIZE_MEDIUM = 16777216; /** - * 2^32-1 + * Schema API big text 4GB (4*2^30). */ - const SIZE_BIG = 4294967295; + const SIZE_BIG = 4294967296; /** * {@inheritdoc} @@ -68,10 +68,10 @@ class JSONItem extends FieldItemBase { '#type' => 'select', '#title' => $this->t('Maximum size'), '#options' => [ - static::SIZE_SMALL => t('255 Byte'), - static::SIZE_NORMAL - 1 => t('64 KB'), - static::SIZE_MEDIUM - 1 => t('16 MB'), - static::SIZE_BIG - 1 => t('4 GB'), + static::SIZE_SMALL => t('255 Characters'), + static::SIZE_NORMAL => t('64 KB'), + static::SIZE_MEDIUM => t('16 MB'), + static::SIZE_BIG => t('4 GB'), ], ]; diff --git a/tests/src/Kernel/JsonItemTest.php b/tests/src/Kernel/JsonItemTest.php index 1516608..356ddf1 100644 --- a/tests/src/Kernel/JsonItemTest.php +++ b/tests/src/Kernel/JsonItemTest.php @@ -9,6 +9,7 @@ namespace Drupal\Tests\json_field\Kernel; use Drupal\Core\Database\Connection; use Drupal\entity_test\Entity\EntityTest; +use Drupal\json_field\Plugin\Field\FieldType\JSONItem; /** * @coversDefaultClass \Drupal\json_field\Plugin\Field\FieldType\JSONItem @@ -74,22 +75,22 @@ class JsonItemTest extends KernelTestBase { public function providerTestSchemaSize() { $data = []; - $data[] = [pow(2, 8) - 1, [ + $data[] = [JSONItem::SIZE_SMALL, [ 'type' => 'varchar', 'not null' => 1, 'length' => 255, ]]; - $data[] = [pow(2, 16) - 1, [ + $data[] = [JSONItem::SIZE_NORMAL, [ 'type' => 'text', 'not null' => 1, 'size' => 'normal', ]]; - $data[] = [pow(2, 24) - 1, [ + $data[] = [JSONItem::SIZE_MEDIUM, [ 'type' => 'text', 'not null' => 1, 'size' => 'medium', ]]; - $data[] = [pow(2, 32) - 1, [ + $data[] = [JSONItem::SIZE_BIG, [ 'type' => 'text', 'not null' => 1, 'size' => 'big',