diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 08e7e19..b4d472a 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -267,15 +267,7 @@ public function toArray() { /** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type */ $entity_type = $this->getEntityType(); - $properties_to_export = $entity_type->getPropertiesToExport(); - if (empty($properties_to_export)) { - $config_name = $entity_type->getConfigPrefix() . '.' . $this->id(); - $definition = $this->getTypedConfig()->getDefinition($config_name); - if (!isset($definition['mapping'])) { - throw new SchemaIncompleteException("Incomplete or missing schema for $config_name"); - } - $properties_to_export = array_combine(array_keys($definition['mapping']), array_keys($definition['mapping'])); - } + $properties_to_export = $this->_getPropertiesToExport(); $id_key = $entity_type->getKey('id'); foreach ($properties_to_export as $property_name => $export_name) { @@ -299,6 +291,37 @@ public function toArray() { } /** + * Gets the config entity properties to export. + * + * If declared on the entity_type annotation 'config_export' this is used. + * Otherwise, configuration schema is checked. + * + * @return array + * A list of entity properties. + * + * @throws \Drupal\Core\Config\Schema\SchemaIncompleteException + * Exception thrown when there is no 'config_export' annotation and there is + * no config schema. + * + * @todo Remove underscore in Drupal 9. + */ + public function _getPropertiesToExport() { + /** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type */ + $entity_type = $this->getEntityType(); + + $properties_to_export = $entity_type->getPropertiesToExport(); + if (empty($properties_to_export)) { + $config_name = $entity_type->getConfigPrefix() . '.' . $this->id(); + $definition = $this->getTypedConfig()->getDefinition($config_name); + if (!isset($definition['mapping'])) { + throw new SchemaIncompleteException("Incomplete or missing schema for $config_name"); + } + $properties_to_export = array_combine(array_keys($definition['mapping']), array_keys($definition['mapping'])); + } + return $properties_to_export; + } + + /** * Gets the typed config manager. * * @return \Drupal\Core\Config\TypedConfigManagerInterface diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php index 3834dae..7da983c 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php @@ -471,10 +471,10 @@ public function updateFromStorageRecord(ConfigEntityInterface $entity, array $va $data = $this->mapFromStorageRecords(array($values)); $updated_entity = current($data); + $properties = $entity->_getPropertiesToExport(); - foreach (array_keys($values) as $property) { - $value = $updated_entity->get($property); - $entity->set($property, $value); + foreach ($properties as $property) { + $entity->set($property, $updated_entity->get($property)); } return $entity;