public function DataDefinitionNormalizer::normalize in Schemata 8
5 methods override DataDefinitionNormalizer::normalize()
- ComplexDataDefinitionNormalizer::normalize in schemata_json_schema/
src/ Normalizer/ json/ ComplexDataDefinitionNormalizer.php - Normalizes an object into a set of arrays/scalars.
- ComplexDataDefinitionNormalizer::normalize in schemata_json_schema/
src/ Normalizer/ jsonapi/ ComplexDataDefinitionNormalizer.php - Normalizes an object into a set of arrays/scalars.
- DataReferenceDefinitionNormalizer::normalize in schemata_json_schema/
src/ Normalizer/ json/ DataReferenceDefinitionNormalizer.php - Normalizes an object into a set of arrays/scalars.
- ListDataDefinitionNormalizer::normalize in schemata_json_schema/
src/ Normalizer/ json/ ListDataDefinitionNormalizer.php - Normalizes an object into a set of arrays/scalars.
- ListDataDefinitionNormalizer::normalize in schemata_json_schema/
src/ Normalizer/ jsonapi/ ListDataDefinitionNormalizer.php - Normalizes an object into a set of arrays/scalars.
File
- schemata_json_schema/
src/ Normalizer/ json/ DataDefinitionNormalizer.php, line 35
Class
- DataDefinitionNormalizer
- Normalizer for DataDefinitionInterface instances.
Namespace
Drupal\schemata_json_schema\Normalizer\jsonCode
public function normalize($entity, $format = NULL, array $context = []) {
/* @var $entity \Drupal\Core\TypedData\DataDefinitionInterface */
// `text source` and `date source` produce objects not supported in the API.
// It is not clear how the API excludes them.
// @todo properly identify and exclude this class of computed objects.
if ($entity
->getSetting('text source') || $entity
->getSetting('date source')) {
return [];
}
$property = $this
->extractPropertyData($entity, $context);
if (!empty($context['parent']) && $context['name'] == 'value') {
if ($maxLength = $context['parent']
->getSetting('max_length')) {
$property['maxLength'] = $maxLength;
}
if (empty($context['parent']
->getSetting('allowed_values_function')) && !empty($context['parent']
->getSetting('allowed_values'))) {
$allowed_values = $context['parent']
->getSetting('allowed_values');
$property['enum'] = array_keys($allowed_values);
}
}
$normalized = [
'properties' => [],
];
$normalized['properties'][$context['name']] = $property;
if ($this
->requiredProperty($entity)) {
$normalized['required'][] = $context['name'];
}
return $normalized;
}