class NodeEntityNormalizer in Default Content Extras 8
Defines a class for normalizing nodes.
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\hal\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
- class \Drupal\hal\Normalizer\ContentEntityNormalizer uses DeprecatedServicePropertyTrait, FieldableEntityNormalizerTrait
- class \Drupal\default_content_extra\Normalizer\NodeEntityNormalizer
- class \Drupal\hal\Normalizer\ContentEntityNormalizer uses DeprecatedServicePropertyTrait, FieldableEntityNormalizerTrait
- class \Drupal\hal\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
Expanded class hierarchy of NodeEntityNormalizer
1 string reference to 'NodeEntityNormalizer'
1 service uses NodeEntityNormalizer
File
- src/
Normalizer/ NodeEntityNormalizer.php, line 17
Namespace
Drupal\default_content_extra\NormalizerView source
class NodeEntityNormalizer extends ContentEntityNormalizer {
/**
* {@inheritdoc}
*/
protected $supportedInterfaceOrClass = 'Drupal\\node\\NodeInterface';
/**
* A config object for the Default Content Extra configuration.
*
* @var \Drupal\Core\Config\Config
*/
protected $config;
/**
* Constructs a NodeEntityNormalizer object.
*
* @param \Drupal\hal\LinkManager\LinkManagerInterface $link_manager
* The hypermedia link manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Entity\EntityTypeRepositoryInterface $entity_type_repository
* The entity type repository.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* A config factory for retrieving required config objects.
*/
public function __construct(LinkManagerInterface $link_manager, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, EntityTypeRepositoryInterface $entity_type_repository, EntityFieldManagerInterface $entity_field_manager, ConfigFactoryInterface $config_factory) {
parent::__construct($link_manager, $entity_type_manager, $module_handler, $entity_type_repository, $entity_field_manager);
$this->config = $config_factory
->get('default_content_extra.settings');
}
/**
* {@inheritdoc}
*/
public function normalize($entity, $format = NULL, array $context = array()) {
$normalized = parent::normalize($entity, $format, $context);
if (!$entity
->isNew() && $this->config
->get('path_alias')) {
$nid = $entity
->id();
$path = Url::fromRoute('entity.node.canonical', [
'node' => $nid,
])
->toString();
// If it's not a system path export it.
if ($path != "/node/{$nid}") {
$normalized['path'] = [
'alias' => $path,
];
}
}
return $normalized;
}
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = NULL, array $context = array()) {
$entity = parent::denormalize($data, $class, $format, $context);
if ($this->config
->get('path_alias')) {
// Add the path alias if it's included.
if (!empty($data['path']['alias'])) {
$entity->path = [
'alias' => $data['path']['alias'],
];
}
}
return $entity;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableNormalizerInterface:: |
constant | Name of key for bubbling cacheability metadata via serialization context. | ||
ContentEntityNormalizer:: |
protected | property | ||
ContentEntityNormalizer:: |
protected | property | The hypermedia link manager. | |
ContentEntityNormalizer:: |
protected | property | The module handler. | |
ContentEntityNormalizer:: |
protected | function | Constructs the entity URI. | 1 |
ContentEntityNormalizer:: |
protected | function | Gets the typed data IDs for a type URI. | |
DeprecatedServicePropertyTrait:: |
public | function | Allows to access deprecated/removed properties. | |
FieldableEntityNormalizerTrait:: |
protected | property | The entity field manager. | |
FieldableEntityNormalizerTrait:: |
protected | property | The entity type manager. | 1 |
FieldableEntityNormalizerTrait:: |
protected | property | The entity type repository. | |
FieldableEntityNormalizerTrait:: |
protected | function | Build the field item value using the incoming data. | 7 |
FieldableEntityNormalizerTrait:: |
protected | function | Denormalizes entity data by denormalizing each field individually. | |
FieldableEntityNormalizerTrait:: |
protected | function | Determines the entity type ID to denormalize as. | |
FieldableEntityNormalizerTrait:: |
protected | function | Denormalizes the bundle property so entity creation can use it. | |
FieldableEntityNormalizerTrait:: |
protected | function | Returns the entity field manager. | |
FieldableEntityNormalizerTrait:: |
protected | function | Gets the entity type definition. | |
FieldableEntityNormalizerTrait:: |
protected | function | Returns the entity type manager. | |
FieldableEntityNormalizerTrait:: |
protected | function | Returns the entity type repository. | |
NodeEntityNormalizer:: |
protected | property | A config object for the Default Content Extra configuration. | |
NodeEntityNormalizer:: |
protected | property |
The interface or class that this Normalizer supports. Overrides ContentEntityNormalizer:: |
|
NodeEntityNormalizer:: |
public | function |
Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize(). Overrides ContentEntityNormalizer:: |
|
NodeEntityNormalizer:: |
public | function |
Normalizes an object into a set of arrays/scalars. Overrides ContentEntityNormalizer:: |
|
NodeEntityNormalizer:: |
public | function |
Constructs a NodeEntityNormalizer object. Overrides ContentEntityNormalizer:: |
|
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:: |
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 |