public function DefaultConfigSerializer::onSerializeConfigEntity in Acquia Content Hub 8.2
The default serializer for config entities basic data.
Parameters
\Drupal\acquia_contenthub\Event\ConfigDataEvent $event: The config data event.
File
- src/
EventSubscriber/ SerializeConfig/ DefaultConfigSerializer.php, line 61
Class
- DefaultConfigSerializer
- Serializes default configuration entities.
Namespace
Drupal\acquia_contenthub\EventSubscriber\SerializeConfigCode
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);
}