FieldDefinitionNormalizer.php in Schemata 8
File
schemata_json_schema/src/Normalizer/json/FieldDefinitionNormalizer.php
View source
<?php
namespace Drupal\schemata_json_schema\Normalizer\json;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
class FieldDefinitionNormalizer extends ListDataDefinitionNormalizer {
protected $supportedInterfaceOrClass = FieldDefinitionInterface::class;
public function normalize($entity, $format = NULL, array $context = []) {
$normalized = parent::normalize($entity, $format, $context);
$default_value = $entity
->getDefaultValueLiteral();
if (!empty($default_value)) {
$normalized['properties'][$context['name']]['default'] = $default_value;
}
$cardinality = $entity
->getFieldStorageDefinition()
->getCardinality();
if ($cardinality != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
$normalized['properties'][$context['name']]['maxItems'] = $cardinality;
}
return $normalized;
}
}