class FieldDefinitionNormalizer in Schemata 8
Same name in this branch
- 8 schemata_json_schema/src/Normalizer/jsonapi/FieldDefinitionNormalizer.php \Drupal\schemata_json_schema\Normalizer\jsonapi\FieldDefinitionNormalizer
- 8 schemata_json_schema/src/Normalizer/json/FieldDefinitionNormalizer.php \Drupal\schemata_json_schema\Normalizer\json\FieldDefinitionNormalizer
- 8 schemata_json_schema/src/Normalizer/hal/FieldDefinitionNormalizer.php \Drupal\schemata_json_schema\Normalizer\hal\FieldDefinitionNormalizer
Normalizer for FieldDefinitionInterface objects.
This normalizes the variant of data fields particular to the Field system. By accessing this via the FieldDefinitionInterface, there is greater access to some of the methods providing deeper schema properties.
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\json\ListDataDefinitionNormalizer
- class \Drupal\schemata_json_schema\Normalizer\json\FieldDefinitionNormalizer
- class \Drupal\schemata_json_schema\Normalizer\json\ListDataDefinitionNormalizer
- 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 FieldDefinitionNormalizer
1 file declares its use of FieldDefinitionNormalizer
- FieldDefinitionNormalizer.php in schemata_json_schema/
src/ Normalizer/ hal/ FieldDefinitionNormalizer.php
1 string reference to 'FieldDefinitionNormalizer'
- 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 FieldDefinitionNormalizer
File
- schemata_json_schema/
src/ Normalizer/ json/ FieldDefinitionNormalizer.php, line 15
Namespace
Drupal\schemata_json_schema\Normalizer\jsonView source
class FieldDefinitionNormalizer extends ListDataDefinitionNormalizer {
/**
* The interface or class that this Normalizer supports.
*
* @var string
*/
protected $supportedInterfaceOrClass = FieldDefinitionInterface::class;
/**
* {@inheritdoc}
*/
public function normalize($entity, $format = NULL, array $context = []) {
/* @var $entity \Drupal\Core\Field\FieldDefinitionInterface */
$normalized = parent::normalize($entity, $format, $context);
// Specify non-contextual default value as an example.
$default_value = $entity
->getDefaultValueLiteral();
if (!empty($default_value)) {
$normalized['properties'][$context['name']]['default'] = $default_value;
}
// The cardinality is the configured maximum number of values the field can
// contain. If unlimited, we do not include a maxItems attribute.
$cardinality = $entity
->getFieldStorageDefinition()
->getCardinality();
if ($cardinality != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
$normalized['properties'][$context['name']]['maxItems'] = $cardinality;
}
return $normalized;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableNormalizerInterface:: |
constant | Name of key for bubbling cacheability metadata via serialization context. | ||
DataDefinitionNormalizer:: |
protected | function | Extracts property details from a data definition. | |
FieldDefinitionNormalizer:: |
protected | property |
The interface or class that this Normalizer supports. Overrides ListDataDefinitionNormalizer:: |
|
FieldDefinitionNormalizer:: |
public | function |
Normalizes an object into a set of arrays/scalars. Overrides ListDataDefinitionNormalizer:: |
|
JsonNormalizerBase:: |
protected | property | The formats that the Normalizer can handle. | 7 |
JsonNormalizerBase:: |
protected | property |
The formats that the Normalizer can handle. Overrides NormalizerBase:: |
7 |
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 |