class ListDataDefinitionNormalizer in Schemata 8
Same name in this branch
- 8 schemata_json_schema/src/Normalizer/jsonapi/ListDataDefinitionNormalizer.php \Drupal\schemata_json_schema\Normalizer\jsonapi\ListDataDefinitionNormalizer
- 8 schemata_json_schema/src/Normalizer/json/ListDataDefinitionNormalizer.php \Drupal\schemata_json_schema\Normalizer\json\ListDataDefinitionNormalizer
- 8 schemata_json_schema/src/Normalizer/hal/ListDataDefinitionNormalizer.php \Drupal\schemata_json_schema\Normalizer\hal\ListDataDefinitionNormalizer
Normalizer for ListDataDefinitionInterface objects.
Almost all entity properties in the system are a list of values, each value in the "List" might be a ComplexDataDefinitionInterface (an object) or it might be more of a scalar.
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait- class \Drupal\schemata\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface- class \Drupal\schemata_json_schema\Normalizer\json\JsonNormalizerBase implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface- class \Drupal\schemata_json_schema\Normalizer\json\DataDefinitionNormalizer- class \Drupal\schemata_json_schema\Normalizer\jsonapi\DataDefinitionNormalizer- class \Drupal\schemata_json_schema\Normalizer\jsonapi\ListDataDefinitionNormalizer
 
 
- class \Drupal\schemata_json_schema\Normalizer\jsonapi\DataDefinitionNormalizer
 
- class \Drupal\schemata_json_schema\Normalizer\json\DataDefinitionNormalizer
 
- class \Drupal\schemata_json_schema\Normalizer\json\JsonNormalizerBase implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
 
- class \Drupal\schemata\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
Expanded class hierarchy of ListDataDefinitionNormalizer
1 string reference to 'ListDataDefinitionNormalizer'
- schemata_json_schema.services.yml in schemata_json_schema/schemata_json_schema.services.yml 
- schemata_json_schema/schemata_json_schema.services.yml
1 service uses ListDataDefinitionNormalizer
File
- schemata_json_schema/src/ Normalizer/ jsonapi/ ListDataDefinitionNormalizer.php, line 16 
Namespace
Drupal\schemata_json_schema\Normalizer\jsonapiView source
class ListDataDefinitionNormalizer extends DataDefinitionNormalizer {
  /**
   * The interface or class that this Normalizer supports.
   *
   * @var string
   */
  protected $supportedInterfaceOrClass = ListDataDefinitionInterface::class;
  /**
   * {@inheritdoc}
   */
  public function normalize($list_data_definition, $format = NULL, array $context = []) {
    assert($list_data_definition instanceof ListDataDefinitionInterface);
    $context['parent'] = $list_data_definition;
    $property = $this
      ->extractPropertyData($list_data_definition, $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($list_data_definition
      ->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($list_data_definition)) {
      $property['minItems'] = 1;
    }
    if ($context['cardinality'] == 1) {
      $single_property = $property['items'];
      unset($property['items']);
      unset($property['type']);
      unset($property['minItems']);
      $single_property = array_merge($single_property, $property);
      $property = $single_property;
    }
    $normalized = [
      'description' => t('Entity attributes'),
      'type' => 'object',
      'properties' => [],
    ];
    $public_name = $context['name'];
    $normalized['properties'][$public_name] = $property;
    if ($this
      ->requiredProperty($list_data_definition)) {
      $normalized['required'][] = $public_name;
    }
    return [
      'type' => 'object',
      'properties' => [
        'attributes' => $normalized,
      ],
    ];
  }
  /**
   * Determine if the current field is a reference field.
   *
   * @param \Drupal\Core\TypedData\ListDataDefinitionInterface $entity
   *   The list definition to be checked.
   *
   * @return bool
   *   TRUE if it is a reference, FALSE otherwise.
   */
  protected function isReferenceField(ListDataDefinitionInterface $entity) {
    $item = $entity
      ->getItemDefinition();
    if ($item instanceof ComplexDataDefinitionInterface) {
      $main = $item
        ->getPropertyDefinition($item
        ->getMainPropertyName());
      // @todo use an interface or API call instead of an object check.
      return $main instanceof DataReferenceTargetDefinition;
    }
    return FALSE;
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| CacheableNormalizerInterface:: | constant | Name of key for bubbling cacheability metadata via serialization context. | ||
| DataDefinitionNormalizer:: | protected | property | The formats that the Normalizer can handle. Overrides JsonNormalizerBase:: | |
| DataDefinitionNormalizer:: | protected | property | The formats that the Normalizer can handle. Overrides JsonNormalizerBase:: | |
| DataDefinitionNormalizer:: | protected | function | Extracts property details from a data definition. | |
| ListDataDefinitionNormalizer:: | protected | property | The interface or class that this Normalizer supports. Overrides DataDefinitionNormalizer:: | 3 | 
| ListDataDefinitionNormalizer:: | protected | function | Determine if the current field is a reference field. | |
| ListDataDefinitionNormalizer:: | public | function | Normalizes an object into a set of arrays/scalars. Overrides DataDefinitionNormalizer:: | 3 | 
| NormalizerBase:: | protected | function | Adds cacheability if applicable. | |
| NormalizerBase:: | protected | function | Checks if the provided format is supported by this normalizer. Overrides NormalizerBase:: | |
| NormalizerBase:: | public | function | Denormalizes data back into an object of the given class. | |
| NormalizerBase:: | protected | function | Normalize an array of data definitions. | |
| NormalizerBase:: | protected | function | Determine if the given property is a required element of the schema. | |
| NormalizerBase:: | public | function | Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() Overrides NormalizerBase:: | |
| NormalizerBase:: | public | function | Checks whether the given class is supported for normalization by this normalizer. | 1 | 
