f6332a36faf0bc9e3d8efb773932c9f3d357c784
[yaffs-website] / web / core / modules / serialization / src / Normalizer / ConfigEntityNormalizer.php
1 <?php
2
3 namespace Drupal\serialization\Normalizer;
4
5 /**
6  * Normalizes/denormalizes Drupal config entity objects into an array structure.
7  */
8 class ConfigEntityNormalizer extends EntityNormalizer {
9
10   /**
11    * The interface or class that this Normalizer supports.
12    *
13    * @var array
14    */
15   protected $supportedInterfaceOrClass = ['Drupal\Core\Config\Entity\ConfigEntityInterface'];
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 }