1<?php 2 3namespace Drupal\serialization\Normalizer; 4 5use Drupal\Core\Config\Entity\ConfigEntityInterface; 6 7/** 8 * Normalizes/denormalizes Drupal config entity objects into an array structure. 9 */ 10class ConfigEntityNormalizer extends EntityNormalizer { 11 12 /** 13 * {@inheritdoc} 14 */ 15 protected $supportedInterfaceOrClass = ConfigEntityInterface::class; 16 17 /** 18 * {@inheritdoc} 19 */ 20 public function normalize($object, $format = NULL, array $context = []) { 21 return static::getDataWithoutInternals($object->toArray()); 22 } 23 24 /** 25 * {@inheritdoc} 26 */ 27 public function denormalize($data, $class, $format = NULL, array $context = []) { 28 return parent::denormalize(static::getDataWithoutInternals($data), $class, $format, $context); 29 } 30 31 /** 32 * Gets the given data without the internal implementation details. 33 * 34 * @param array $data 35 * The data that is either currently or about to be stored in configuration. 36 * 37 * @return array 38 * The same data, but without internals. Currently, that is only the '_core' 39 * key, which is reserved by Drupal core to handle complex edge cases 40 * correctly. Data in the '_core' key is irrelevant to clients reading 41 * configuration, and is not allowed to be set by clients writing 42 * configuration: it is for Drupal core only, and managed by Drupal core. 43 * 44 * @see https://www.drupal.org/node/2653358 45 */ 46 protected static function getDataWithoutInternals(array $data) { 47 return array_diff_key($data, ['_core' => TRUE]); 48 } 49 50} 51