ContentEntityNormalizer.php in Drupal 8
Same filename in this branch
Same filename and directory in other branches
Namespace
Drupal\serialization\NormalizerFile
core/modules/serialization/src/Normalizer/ContentEntityNormalizer.phpView source
<?php
namespace Drupal\serialization\Normalizer;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\TypedData\TypedDataInternalPropertiesHelper;
/**
* Normalizes/denormalizes Drupal content entities into an array structure.
*/
class ContentEntityNormalizer extends EntityNormalizer {
/**
* {@inheritdoc}
*/
protected $supportedInterfaceOrClass = ContentEntityInterface::class;
/**
* {@inheritdoc}
*/
public function normalize($entity, $format = NULL, array $context = []) {
$context += [
'account' => NULL,
];
$attributes = [];
/** @var \Drupal\Core\Entity\Entity $entity */
foreach (TypedDataInternalPropertiesHelper::getNonInternalProperties($entity
->getTypedData()) as $name => $field_items) {
if ($field_items
->access('view', $context['account'])) {
$attributes[$name] = $this->serializer
->normalize($field_items, $format, $context);
}
}
return $attributes;
}
}
Classes
Name | Description |
---|---|
ContentEntityNormalizer | Normalizes/denormalizes Drupal content entities into an array structure. |