class FieldItemNormalizer in JSON:API Extras 8
Same name and namespace in other branches
- 8.3 src/Normalizer/FieldItemNormalizer.php \Drupal\jsonapi_extras\Normalizer\FieldItemNormalizer
- 8.2 src/Normalizer/FieldItemNormalizer.php \Drupal\jsonapi_extras\Normalizer\FieldItemNormalizer
Converts the Drupal field structure to a JSON API array structure.
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\jsonapi\Normalizer\NormalizerBase
- class \Drupal\jsonapi_extras\Normalizer\FieldItemNormalizer
- class \Drupal\jsonapi\Normalizer\NormalizerBase
Expanded class hierarchy of FieldItemNormalizer
1 string reference to 'FieldItemNormalizer'
1 service uses FieldItemNormalizer
File
- src/
Normalizer/ FieldItemNormalizer.php, line 15
Namespace
Drupal\jsonapi_extras\NormalizerView source
class FieldItemNormalizer extends NormalizerBase {
/**
* The interface or class that this Normalizer supports.
*
* @var string
*/
protected $supportedInterfaceOrClass = FieldItemInterface::class;
/**
* The JSON API field normalizer entity.
*
* @var \Drupal\jsonapi\Normalizer\FieldItemNormalizer
*/
protected $subject;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The field enhancer manager.
*
* @var \Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerManager
*/
protected $enhancerManager;
/**
* Constructs a new FieldItemNormalizer.
*
* @param \Drupal\jsonapi\Normalizer\FieldItemNormalizer $subject
* The JSON API field normalizer entity.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerManager $enhancer_manager
* The field enhancer manager.
*/
public function __construct(JsonapiFieldItemNormalizer $subject, EntityTypeManagerInterface $entity_type_manager, ResourceFieldEnhancerManager $enhancer_manager) {
$this->subject = $subject;
$this->entityTypeManager = $entity_type_manager;
$this->enhancerManager = $enhancer_manager;
}
/**
* {@inheritdoc}
*/
public function normalize($object, $format = NULL, array $context = []) {
// First get the regular output.
$normalized_output = $this->subject
->normalize($object, $format, $context);
// Then detect if there is any enhancer to be applied here.
/** @var \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType $resource_type */
$resource_type = $context['resource_type'];
$enhancer = $resource_type
->getFieldEnhancer($object
->getParent()
->getName());
if (!$enhancer) {
return $normalized_output;
}
// Apply any enhancements necessary.
$processed = $enhancer
->postProcess($normalized_output
->rasterizeValue());
$normalized_output = new FieldItemNormalizerValue([
$processed,
]);
return $normalized_output;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableNormalizerInterface:: |
constant | Name of key for bubbling cacheability metadata via serialization context. | ||
FieldItemNormalizer:: |
protected | property | The field enhancer manager. | |
FieldItemNormalizer:: |
protected | property | The entity type manager. | |
FieldItemNormalizer:: |
protected | property | The JSON API field normalizer entity. | |
FieldItemNormalizer:: |
protected | property |
The interface or class that this Normalizer supports. Overrides NormalizerBase:: |
|
FieldItemNormalizer:: |
public | function | Normalizes an object into a set of arrays/scalars. | |
FieldItemNormalizer:: |
public | function | Constructs a new FieldItemNormalizer. | |
NormalizerBase:: |
protected | property |
List of formats which supports (de-)normalization. Overrides NormalizerBase:: |
|
NormalizerBase:: |
protected | function | Adds cacheability if applicable. | |
NormalizerBase:: |
protected | function |
Checks if the provided format is supported by this normalizer. Overrides NormalizerBase:: |
|
NormalizerBase:: |
protected static | function | Rasterizes a value recursively. | |
NormalizerBase:: |
public | function | Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() | 1 |
NormalizerBase:: |
public | function | Checks whether the given class is supported for normalization by this normalizer. | 1 |