ConfigItemNormalizer.php in Configuration Normalizer 8
File
src/ConfigItemNormalizer.php
View source
<?php
namespace Drupal\config_normalizer;
use Drupal\Component\Plugin\PluginManagerInterface;
class ConfigItemNormalizer implements ConfigItemNormalizerInterface {
protected $normalizerManager;
protected $normalizers;
public function __construct(PluginManagerInterface $normalizer_manager) {
$this->normalizerManager = $normalizer_manager;
}
public function normalize($name, array $data, array $context = []) {
$normalizers = $this->normalizerManager
->getDefinitions();
uasort($normalizers, [
'Drupal\\Component\\Utility\\SortArray',
'sortByWeightElement',
]);
foreach (array_keys($normalizers) as $id) {
$this
->applyNormalizer($id, $name, $data, $context);
}
return $data;
}
protected function applyNormalizer($id, $name, array &$data, array $context) {
$normalizer = $this
->getNormalizerInstance($id);
$normalizer
->normalize($name, $data, $context);
}
protected function getNormalizerInstance($id) {
if (!isset($this->normalizers[$id])) {
$instance = $this->normalizerManager
->createInstance($id);
$this->normalizers[$id] = $instance;
}
return $this->normalizers[$id];
}
}