abstract class EntityDenormalizerBase in Drupal 8
Same name and namespace in other branches
- 9 core/modules/jsonapi/src/Normalizer/EntityDenormalizerBase.php \Drupal\jsonapi\Normalizer\EntityDenormalizerBase
Converts the Drupal entity object to a JSON:API array structure.
@internal JSON:API maintains no PHP API since its API is the HTTP API. This class may change at any time and this will break any dependencies on it.
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\Normalizer\EntityDenormalizerBase implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
- class \Drupal\jsonapi\Normalizer\NormalizerBase
Expanded class hierarchy of EntityDenormalizerBase
See also
https://www.drupal.org/project/drupal/issues/3032787
File
- core/
modules/ jsonapi/ src/ Normalizer/ EntityDenormalizerBase.php, line 21
Namespace
Drupal\jsonapi\NormalizerView source
abstract class EntityDenormalizerBase extends NormalizerBase implements DenormalizerInterface {
/**
* The JSON:API resource type repository.
*
* @var \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface
*/
protected $resourceTypeRepository;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $fieldManager;
/**
* The field plugin manager.
*
* @var \Drupal\Core\Field\FieldTypePluginManagerInterface
*/
protected $pluginManager;
/**
* Constructs an EntityDenormalizerBase object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $field_manager
* The entity field manager.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $plugin_manager
* The plugin manager for fields.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $field_manager, FieldTypePluginManagerInterface $plugin_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->fieldManager = $field_manager;
$this->pluginManager = $plugin_manager;
}
/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = NULL) {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function normalize($object, $format = NULL, array $context = []) {
throw new \LogicException('This method should never be called.');
}
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = NULL, array $context = []) {
if (empty($context['resource_type']) || !$context['resource_type'] instanceof ResourceType) {
throw new PreconditionFailedHttpException('Missing context during denormalization.');
}
/* @var \Drupal\jsonapi\ResourceType\ResourceType $resource_type */
$resource_type = $context['resource_type'];
$entity_type_id = $resource_type
->getEntityTypeId();
$bundle = $resource_type
->getBundle();
$bundle_key = $this->entityTypeManager
->getDefinition($entity_type_id)
->getKey('bundle');
if ($bundle_key && $bundle) {
$data[$bundle_key] = $bundle;
}
return $this->entityTypeManager
->getStorage($entity_type_id)
->create($this
->prepareInput($data, $resource_type, $format, $context));
}
/**
* Prepares the input data to create the entity.
*
* @param array $data
* The input data to modify.
* @param \Drupal\jsonapi\ResourceType\ResourceType $resource_type
* Contains the info about the resource type.
* @param string $format
* Format the given data was extracted from.
* @param array $context
* Options available to the denormalizer.
*
* @return array
* The modified input data.
*/
protected abstract function prepareInput(array $data, ResourceType $resource_type, $format, array $context);
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableNormalizerInterface:: |
constant | Name of key for bubbling cacheability metadata via serialization context. | ||
EntityDenormalizerBase:: |
protected | property | The entity type manager. | |
EntityDenormalizerBase:: |
protected | property | The entity field manager. | |
EntityDenormalizerBase:: |
protected | property | The field plugin manager. | |
EntityDenormalizerBase:: |
protected | property | The JSON:API resource type repository. | |
EntityDenormalizerBase:: |
public | function | Denormalizes data back into an object of the given class. | |
EntityDenormalizerBase:: |
public | function | Normalizes an object into a set of arrays/scalars. | |
EntityDenormalizerBase:: |
abstract protected | function | Prepares the input data to create the entity. | 2 |
EntityDenormalizerBase:: |
public | function |
Checks whether the given class is supported for normalization by this normalizer. Overrides NormalizerBase:: |
|
EntityDenormalizerBase:: |
public | function | Constructs an EntityDenormalizerBase object. | |
NormalizerBase:: |
protected | property |
List of formats which supports (de-)normalization. Overrides NormalizerBase:: |
|
NormalizerBase:: |
protected | property | The interface or class that this Normalizer supports. | 22 |
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 |