class WorkspaceNormalizer in Replication 8.2
Same name and namespace in other branches
- 8 src/Normalizer/WorkspaceNormalizer.php \Drupal\replication\Normalizer\WorkspaceNormalizer
Workspace entity normalizer and denormalizer.
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\replication\Normalizer\WorkspaceNormalizer implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
Expanded class hierarchy of WorkspaceNormalizer
1 string reference to 'WorkspaceNormalizer'
1 service uses WorkspaceNormalizer
File
- src/
Normalizer/ WorkspaceNormalizer.php, line 14
Namespace
Drupal\replication\NormalizerView source
class WorkspaceNormalizer extends NormalizerBase implements DenormalizerInterface {
/**
* @var string[]
*/
protected $supportedInterfaceOrClass = [
'Drupal\\multiversion\\Entity\\WorkspaceInterface',
];
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs an EntityNormalizer object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public function normalize($entity, $format = NULL, array $context = []) {
$context['entity_type'] = 'workspace';
$return_data = [];
if ($machine_name = (string) $entity
->getMachineName()) {
$return_data['db_name'] = $machine_name;
}
if ($update_seq = $entity
->getUpdateSeq()) {
$return_data['update_seq'] = (int) $update_seq;
}
else {
// Replicator expects update_seq to be always set.
$return_data['update_seq'] = 0;
}
if ($created = (string) $entity
->getStartTime()) {
$return_data['instance_start_time'] = $created;
}
return $return_data;
}
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = NULL, array $context = []) {
if (isset($data['db_name'])) {
$data['machine_name'] = $data['db_name'];
unset($data['db_name']);
}
if (isset($data['instance_start_time'])) {
$data['created'] = $data['instance_start_time'];
unset($data['instance_start_time']);
}
$workspace_types = WorkspaceType::loadMultiple();
$workspace_type = reset($workspace_types);
if (!$workspace_type instanceof WorkspaceTypeInterface) {
throw new \Exception('Invalid workspace type.');
}
$data['type'] = $workspace_type
->id();
return $this->entityTypeManager
->getStorage('workspace')
->create($data);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableNormalizerInterface:: |
constant | Name of key for bubbling cacheability metadata via serialization context. | ||
NormalizerBase:: |
protected | property | List of formats which supports (de-)normalization. | 3 |
NormalizerBase:: |
protected | function | Adds cacheability if applicable. | |
NormalizerBase:: |
protected | function | Checks if the provided format is supported by this normalizer. | 2 |
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 |
WorkspaceNormalizer:: |
protected | property | The entity manager. | |
WorkspaceNormalizer:: |
protected | property |
Overrides NormalizerBase:: |
|
WorkspaceNormalizer:: |
public | function | Denormalizes data back into an object of the given class. | |
WorkspaceNormalizer:: |
public | function | Normalizes an object into a set of arrays/scalars. | |
WorkspaceNormalizer:: |
public | function | Constructs an EntityNormalizer object. |