Skip to content
Snippets Groups Projects
Commit 53068d07 authored by catch's avatar catch
Browse files

Issue #2191903 by damiankloip: Provide a ConfigEntityNormalizer.

parent a60a5b87
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
<?php
/**
* @file
* Contains \Drupal\serialization\Normalizer\ConfigEntityNormalizer.
*/
namespace Drupal\serialization\Normalizer;
/**
* Normalizes/denormalizes Drupal config entity objects into an array structure.
*/
class ConfigEntityNormalizer extends EntityNormalizer {
/**
* The interface or class that this Normalizer supports.
*
* @var array
*/
protected $supportedInterfaceOrClass = array('Drupal\Core\Config\Entity\ConfigEntityInterface');
/**
* {@inheritdoc}
*/
public function normalize($object, $format = NULL, array $context = array()) {
return $object->getExportProperties();
}
}
......@@ -2,6 +2,11 @@ services:
serializer:
class: Symfony\Component\Serializer\Serializer
arguments: [{ }, { }]
serializer.normalizer.config_entity:
class: Drupal\serialization\Normalizer\ConfigEntityNormalizer
tags:
- { name: normalizer }
arguments: ['@entity.manager']
serializer.normalizer.entity:
class: Drupal\serialization\Normalizer\EntityNormalizer
tags:
......
<?php
/**
* @file
* Contains \Drupal\serialization\Tests\Normalizer\ConfigNormalizerTest.
*/
namespace Drupal\serialization\Tests\Normalizer;
use Drupal\serialization\Normalizer\ConfigEntityNormalizer;
use Drupal\Tests\UnitTestCase;
/**
* Tests the ConfigEntityNormalizer class.
*
* @group Serialization
*
* @coversDefaultClass \Drupal\serialization\Normalizer\ConfigEntityNormalizer
*/
class ConfigEntityNormalizerTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'ConfigEntityNormalizer',
'description' => 'Tests the ConfigEntityNormalizer class.',
'group' => 'Serialization',
);
}
/**
* Tests the normalize() method.
*
* @covers ::normalize
*/
public function testNormalize() {
$test_export_properties = array('test' => 'test');
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$normalizer = new ConfigEntityNormalizer($entity_manager);
$config_entity = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityInterface');
$config_entity->expects($this->once())
->method('getExportProperties')
->will($this->returnValue($test_export_properties));
$this->assertSame($test_export_properties, $normalizer->normalize($config_entity));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment