class SchemataSchemaNormalizer in Schemata 8
Same name in this branch
- 8 schemata_json_schema/src/Normalizer/jsonapi/SchemataSchemaNormalizer.php \Drupal\schemata_json_schema\Normalizer\jsonapi\SchemataSchemaNormalizer
- 8 schemata_json_schema/src/Normalizer/json/SchemataSchemaNormalizer.php \Drupal\schemata_json_schema\Normalizer\json\SchemataSchemaNormalizer
- 8 schemata_json_schema/src/Normalizer/hal/SchemataSchemaNormalizer.php \Drupal\schemata_json_schema\Normalizer\hal\SchemataSchemaNormalizer
Extends the base SchemataSchema normalizer for JSON with HAL+JSON elements.
The main distinction between HAL+JSON and HAL is the addition of _links for hyperlink relations and _embedded to inline partial or complete examples of the related entities. Therefore HAL serialization shares many of the same Normalizer classes as JSON, except in this "entrypoint" normalizer and the handling of references.
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\SchemataSchemaNormalizer
- class \Drupal\schemata_json_schema\Normalizer\hal\SchemataSchemaNormalizer
- class \Drupal\schemata_json_schema\Normalizer\json\SchemataSchemaNormalizer
- 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 SchemataSchemaNormalizer
1 string reference to 'SchemataSchemaNormalizer'
- 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 SchemataSchemaNormalizer
File
- schemata_json_schema/
src/ Normalizer/ hal/ SchemataSchemaNormalizer.php, line 16
Namespace
Drupal\schemata_json_schema\Normalizer\halView source
class SchemataSchemaNormalizer extends JsonSchemataSchemaNormalizer {
/**
* The formats that the Normalizer can handle.
*
* @var array
*/
protected $format = 'schema_json';
/**
* The formats that the Normalizer can handle.
*
* @var array
*/
protected $describedFormat = 'hal_json';
/**
* {@inheritdoc}
*/
public function normalize($entity, $format = NULL, array $context = []) {
// Create the array of normalized fields, starting with the URI.
/* @var $entity \Drupal\schemata\Schema\SchemaInterface */
$normalized = parent::normalize($entity, $format, $context);
// HAL link schema definitions based on HyperSchema.org.
// @see http://hyperschema.org/mediatypes/hal
$items = [];
if (!empty($normalized['properties']['_links'])) {
$items = $normalized['properties']['_links'];
}
$items['self'] = [
'$ref' => '#/definitions/linkObject',
];
$items['type'] = [
'$ref' => '#/definitions/linkObject',
];
$normalized['properties']['_links'] = [
'title' => 'HAL Links',
'description' => 'Object of links with the rels as the keys',
'type' => 'object',
'properties' => $items,
];
if (!empty($normalized['properties']['_embedded'])) {
$items = $normalized['properties']['_embedded'];
$normalized['properties']['_embedded'] = [
'title' => 'HAL Embedded Resource',
'description' => 'An embedded HAL resource',
'type' => 'object',
'properties' => $items,
];
}
$normalized['definitions']['linkArray'] = [
'title' => 'HAL Link Array',
'description' => 'An array of linkObjects of the same link relation',
'type' => 'array',
'items' => [
'$ref' => '#/definitions/linkObject',
],
];
// Drupal core does not currently use several HAL link attributes.
// If they are added entries should be added here.
$normalized['definitions']['linkObject'] = [
'title' => 'HAL Link Object',
'description' => 'An object with link information.',
'type' => 'object',
'properties' => [
'name' => [
'title' => 'Name',
'description' => 'Name of a resource, link, action, etc.',
'type' => 'string',
],
'title' => [
'title' => 'Title',
'description' => 'A title for a resource, link, action, etc.',
'type' => 'string',
],
'href' => [
'title' => 'HREF',
'description' => 'A hyperlink URL.',
'type' => 'string',
'format' => 'uri',
],
],
'required' => [
'href',
],
];
return $normalized;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableNormalizerInterface:: |
constant | Name of key for bubbling cacheability metadata via serialization context. | ||
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 |
SchemataSchemaNormalizer:: |
protected | property |
The formats that the Normalizer can handle. Overrides JsonNormalizerBase:: |
|
SchemataSchemaNormalizer:: |
protected | property |
The formats that the Normalizer can handle. Overrides JsonNormalizerBase:: |
|
SchemataSchemaNormalizer:: |
protected | property |
The interface or class that this Normalizer supports. Overrides NormalizerBase:: |
|
SchemataSchemaNormalizer:: |
protected static | function | Identify properties of the data definition to normalize. | |
SchemataSchemaNormalizer:: |
public | function |
Normalizes an object into a set of arrays/scalars. Overrides SchemataSchemaNormalizer:: |