public function ListDataDefinitionNormalizer::normalize in Schemata 8
Same name in this branch
- 8 schemata_json_schema/src/Normalizer/jsonapi/ListDataDefinitionNormalizer.php \Drupal\schemata_json_schema\Normalizer\jsonapi\ListDataDefinitionNormalizer::normalize()
- 8 schemata_json_schema/src/Normalizer/json/ListDataDefinitionNormalizer.php \Drupal\schemata_json_schema\Normalizer\json\ListDataDefinitionNormalizer::normalize()
Overrides DataDefinitionNormalizer::normalize
1 call to ListDataDefinitionNormalizer::normalize()
- FieldDefinitionNormalizer::normalize in schemata_json_schema/
src/ Normalizer/ json/ FieldDefinitionNormalizer.php - Normalizes an object into a set of arrays/scalars.
1 method overrides ListDataDefinitionNormalizer::normalize()
- FieldDefinitionNormalizer::normalize in schemata_json_schema/
src/ Normalizer/ json/ FieldDefinitionNormalizer.php - Normalizes an object into a set of arrays/scalars.
File
- schemata_json_schema/
src/ Normalizer/ json/ ListDataDefinitionNormalizer.php, line 28
Class
- ListDataDefinitionNormalizer
- Normalizer for ListDataDefinitionInterface objects.
Namespace
Drupal\schemata_json_schema\Normalizer\jsonCode
public function normalize($entity, $format = NULL, array $context = []) {
/* @var $entity \Drupal\Core\TypedData\ListDataDefinitionInterface */
$context['parent'] = $entity;
$property = $this
->extractPropertyData($entity, $context);
$property['type'] = 'array';
// This retrieves the definition common to ever item in the list, and
// serializes it so we can define how members of the array should look.
// There are no lists that might contain items of different types.
$property['items'] = $this->serializer
->normalize($entity
->getItemDefinition(), $format, $context);
// FieldDefinitionInterface::isRequired() explicitly indicates there must be
// at least one item in the list. Extending this reasoning, the same must be
// true of all ListDataDefinitions.
if ($this
->requiredProperty($entity)) {
$property['minItems'] = 1;
}
$normalized = [
'properties' => [],
];
$normalized['properties'][$context['name']] = $property;
if ($this
->requiredProperty($entity)) {
$normalized['required'][] = $context['name'];
}
return $normalized;
}