class DefaultConfigSerializer in Acquia Content Hub 8.2
Serializes default configuration entities.
Hierarchy
- class \Drupal\acquia_contenthub\EventSubscriber\SerializeConfig\DefaultConfigSerializer implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of DefaultConfigSerializer
1 string reference to 'DefaultConfigSerializer'
1 service uses DefaultConfigSerializer
File
- src/
EventSubscriber/ SerializeConfig/ DefaultConfigSerializer.php, line 16
Namespace
Drupal\acquia_contenthub\EventSubscriber\SerializeConfigView source
class DefaultConfigSerializer implements EventSubscriberInterface {
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The language manager service.
*
* @var \Drupal\Core\Language\LanguageManagerInterface|\Drupal\language\ConfigurableLanguageManagerInterface
*/
protected $languageManager;
/**
* DefaultConfigSerializer constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, LanguageManagerInterface $language_manager) {
$this->configFactory = $config_factory;
$this->languageManager = $language_manager;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = [];
$events[AcquiaContentHubEvents::SERIALIZE_CONFIG_ENTITY][] = [
'onSerializeConfigEntity',
];
return $events;
}
/**
* The default serializer for config entities basic data.
*
* @param \Drupal\acquia_contenthub\Event\ConfigDataEvent $event
* The config data event.
*/
public function onSerializeConfigEntity(ConfigDataEvent $event) {
$entity = $event
->getEntity();
$entity_type = $entity
->getEntityType();
$config_name = $entity_type
->getConfigPrefix() . '.' . $entity
->get($entity_type
->getKey('id'));
$config = $this->configFactory
->get($config_name);
$data = $event
->getData();
// Use NestedArray::mergeDeepArray() and preserve the integer keys to
// prevent overriding or duplicating any config data that was already
// serialized by other handlers. We duplicate this approach for language
// overrides.
$data[$entity
->language()
->getId()] = !empty($data[$entity
->language()
->getId()]) ? NestedArray::mergeDeepArray([
$data[$entity
->language()
->getId()],
$config
->getRawData(),
], TRUE) : $config
->getRawData();
if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) {
foreach ($this->languageManager
->getLanguages() as $langcode => $language) {
if ($langcode === $entity
->language()
->getId()) {
continue;
}
/** @var \Drupal\language\Config\LanguageConfigOverride $language_config_override */
$language_config_override = $this->languageManager
->getLanguageConfigOverride($langcode, $config_name);
$overridden_config = $language_config_override
->get();
if ($overridden_config) {
$data[$langcode] = !empty($data[$langcode]) ? NestedArray::mergeDeepArray([
$data[$langcode],
$overridden_config,
], TRUE) : $overridden_config;
}
}
}
$event
->setData($data);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DefaultConfigSerializer:: |
protected | property | The configuration factory. | |
DefaultConfigSerializer:: |
protected | property | The language manager service. | |
DefaultConfigSerializer:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
DefaultConfigSerializer:: |
public | function | The default serializer for config entities basic data. | |
DefaultConfigSerializer:: |
public | function | DefaultConfigSerializer constructor. |