NativeJSONItem.php in JSON Field 8
File
src/Plugin/Field/FieldType/NativeJSONItem.php
View source
<?php
namespace Drupal\json_field\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
class NativeJSONItem extends FieldItemBase {
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'value' => [
'type' => 'json',
'pgsql_type' => 'json',
'mysql_type' => 'json',
'not null' => FALSE,
],
],
];
}
public function isEmpty() {
$value = $this
->get('value')
->getValue();
return $value === NULL || $value === '';
}
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('string')
->setLabel(t('JSON value'));
return $properties;
}
}