You are here

protected function SchemataSchemaNormalizer::normalizeJsonapiProperties in Schemata 8

Normalize an array of data definitions.

This normalization process gets an array of properties and an array of properties that are required by name. This is needed by the SchemataSchemaNormalizer, otherwise it would have been placed in DataDefinitionNormalizer.

Parameters

\Drupal\Core\TypedData\DataDefinitionInterface[] $items: An array of data definition properties to be normalized.

string $format: Format identifier of the current serialization process.

array $context: Operating context of the serializer.

Return value

array Array containing one or two nested arrays.

  • properties: The array of all normalized properties.
  • required: The array of required properties by name.
1 call to SchemataSchemaNormalizer::normalizeJsonapiProperties()
SchemataSchemaNormalizer::normalize in schemata_json_schema/src/Normalizer/jsonapi/SchemataSchemaNormalizer.php
Normalizes an object into a set of arrays/scalars.

File

schemata_json_schema/src/Normalizer/jsonapi/SchemataSchemaNormalizer.php, line 213

Class

SchemataSchemaNormalizer
Primary normalizer for SchemaInterface objects.

Namespace

Drupal\schemata_json_schema\Normalizer\jsonapi

Code

protected function normalizeJsonapiProperties(array $items, $format, array $context = []) {
  $normalized = [];
  $resource_type = $context['resourceType'];
  assert($resource_type instanceof ResourceType);
  assert($this->serializer instanceof NormalizerInterface);
  foreach ($items as $name => $property) {
    if (!$resource_type
      ->isFieldEnabled($name)) {
      continue;
    }
    $context['name'] = $resource_type
      ->getPublicName($name);
    $item = $this->serializer
      ->normalize($property, $format, $context);
    if (!empty($item)) {
      $normalized = NestedArray::mergeDeep($normalized, $item);
    }
  }
  return $normalized;
}