ContentEntityNormalizer.php in Tome 8
File
modules/tome_sync/src/Normalizer/ContentEntityNormalizer.php
View source
<?php
namespace Drupal\tome_sync\Normalizer;
use Drupal\serialization\Normalizer\ContentEntityNormalizer as BaseContentEntityNormalizer;
class ContentEntityNormalizer extends BaseContentEntityNormalizer {
protected $fieldDenyList = [
'metatag',
];
protected $entityTypeDenyList = [
'entity_revision_parent_type_field',
'entity_revision_parent_id_field',
'entity_revision_parent_field_name_field',
];
public function normalize($entity, $format = NULL, array $context = []) {
$values = parent::normalize($entity, $format, $context);
$entity_type = $entity
->getEntityType();
$id_key = $entity_type
->getKey('id');
if ($entity_type
->id() !== 'user' && $id_key && isset($values[$id_key])) {
unset($values[$id_key]);
}
$id_key = $entity_type
->getKey('revision');
if ($id_key && isset($values[$id_key])) {
unset($values[$id_key]);
}
foreach ($this->fieldDenyList as $field_name) {
if (isset($values[$field_name])) {
unset($values[$field_name]);
}
}
foreach ($this->entityTypeDenyList as $key) {
$field_name = $entity
->getEntityType()
->get($key);
if ($field_name && isset($values[$field_name])) {
unset($values[$field_name]);
}
}
return $values;
}
}