class SchemaFieldDefinitionNormalizer in JSON:API Extras 8.3
Same name and namespace in other branches
- 8 src/Normalizer/SchemaFieldDefinitionNormalizer.php \Drupal\jsonapi_extras\Normalizer\SchemaFieldDefinitionNormalizer
- 8.2 src/Normalizer/SchemaFieldDefinitionNormalizer.php \Drupal\jsonapi_extras\Normalizer\SchemaFieldDefinitionNormalizer
Applies field enhancer schema changes to field schema.
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\FieldDefinitionNormalizer
- class \Drupal\jsonapi_extras\Normalizer\SchemaFieldDefinitionNormalizer
- class \Drupal\schemata_json_schema\Normalizer\jsonapi\FieldDefinitionNormalizer
- 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 SchemaFieldDefinitionNormalizer
File
- src/
Normalizer/ SchemaFieldDefinitionNormalizer.php, line 14
Namespace
Drupal\jsonapi_extras\NormalizerView source
class SchemaFieldDefinitionNormalizer extends SchemataJsonSchemaFieldDefinitionNormalizer {
/**
* The JSON:API resource type repository.
*
* @var \Drupal\jsonapi\ResourceType\ResourceTypeRepository
*/
protected $resourceTypeRepository;
/**
* Constructs a SchemaFieldDefinitionNormalizer object.
*
* @param \Drupal\jsonapi\ResourceType\ResourceTypeRepository $resource_type_repository
* A resource type repository.
*/
public function __construct(ResourceTypeRepository $resource_type_repository) {
$this->resourceTypeRepository = $resource_type_repository;
}
/**
* {@inheritdoc}
*/
public function normalize($field_definition, $format = NULL, array $context = []) {
assert($field_definition instanceof FieldDefinitionInterface);
$normalized = parent::normalize($field_definition, $format, $context);
// Load the resource type for this entity type and bundle.
$bundle = empty($context['bundleId']) ? $context['entityTypeId'] : $context['bundleId'];
$resource_type = $this->resourceTypeRepository
->get($context['entityTypeId'], $bundle);
if (!$resource_type || !$resource_type instanceof ConfigurableResourceType) {
return $normalized;
}
$field_name = $context['name'];
$enhancer = $resource_type
->getFieldEnhancer($field_definition
->getName());
if (!$enhancer) {
return $normalized;
}
$parents = [
'properties',
'attributes',
'properties',
$field_name,
];
$original_field_schema = NestedArray::getValue($normalized, $parents);
$to_copy = [
'title',
'description',
];
$field_schema = array_merge($enhancer
->getOutputJsonSchema(), array_intersect_key($original_field_schema, array_flip($to_copy)));
NestedArray::setValue($normalized, $parents, $field_schema);
return $normalized;
}
}
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. | |
FieldDefinitionNormalizer:: |
protected | property |
The interface or class that this Normalizer supports. Overrides ListDataDefinitionNormalizer:: |
|
ListDataDefinitionNormalizer:: |
protected | function | Determine if the current field is a reference field. | |
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 |
SchemaFieldDefinitionNormalizer:: |
protected | property | The JSON:API resource type repository. | |
SchemaFieldDefinitionNormalizer:: |
public | function |
Normalizes an object into a set of arrays/scalars. Overrides FieldDefinitionNormalizer:: |
|
SchemaFieldDefinitionNormalizer:: |
public | function | Constructs a SchemaFieldDefinitionNormalizer object. |