Commit 16efa3be authored by catch's avatar catch
Browse files

Issue #2986901 by gabesullice, alexpott: Followup for #2666392:...

Issue #2986901 by gabesullice, alexpott: Followup for #2666392: ConfigEntityTypeInterface::getPropertiesToExport no longer returns NULL, throws exception instead
parent e41655d1
......@@ -4,6 +4,7 @@
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\Schema\SchemaIncompleteException;
use Drupal\Core\Entity\Entity;
use Drupal\Core\Config\ConfigDuplicateUUIDException;
use Drupal\Core\Entity\EntityStorageInterface;
......@@ -267,7 +268,12 @@ public function toArray() {
$entity_type = $this->getEntityType();
$id_key = $entity_type->getKey('id');
foreach ($entity_type->getPropertiesToExport($this->id()) as $property_name => $export_name) {
$property_names = $entity_type->getPropertiesToExport($this->id());
if (empty($property_names)) {
$config_name = $entity_type->getConfigPrefix() . '.' . $this->id();
throw new SchemaIncompleteException("Incomplete or missing schema for $config_name");
}
foreach ($property_names as $property_name => $export_name) {
// Special handling for IDs so that computed compound IDs work.
// @see \Drupal\Core\Entity\EntityDisplayBase::id()
if ($property_name == $id_key) {
......
......@@ -453,7 +453,15 @@ public function updateFromStorageRecord(ConfigEntityInterface $entity, array $va
/** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type */
$entity_type = $this->getEntityType();
$id_key = $entity_type->getKey('id');
foreach ($entity_type->getPropertiesToExport($updated_entity->get($id_key)) as $property) {
$properties = $entity_type->getPropertiesToExport($updated_entity->get($id_key));
if (empty($properties)) {
// Fallback to using the provided values. If the properties cannot be
// determined for the config entity type annotation or configuration
// schema.
$properties = array_keys($values);
}
foreach ($properties as $property) {
if ($property === $this->uuidKey) {
// During an update the UUID field should not be copied. Under regular
// circumstances the values will be equal. If configuration is written
......
......@@ -3,7 +3,6 @@
namespace Drupal\Core\Config\Entity;
use Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException;
use Drupal\Core\Config\Schema\SchemaIncompleteException;
use Drupal\Core\Entity\EntityType;
use Drupal\Core\Config\ConfigPrefixLengthException;
......@@ -172,7 +171,7 @@ public function getPropertiesToExport($id = NULL) {
$config_name = $this->getConfigPrefix() . '.' . $id;
$definition = \Drupal::service('config.typed')->getDefinition($config_name);
if (!isset($definition['mapping'])) {
throw new SchemaIncompleteException("Incomplete or missing schema for $config_name");
return NULL;
}
$this->mergedConfigExport = array_combine(array_keys($definition['mapping']), array_keys($definition['mapping']));
}
......
......@@ -68,17 +68,13 @@ public function getConfigPrefix();
* Falls back to determining the properties using configuration schema, if the
* config entity properties are not declared.
*
* param string $id
* @param string $id
* The ID of the configuration entity. Used when checking schema instead of
* the annotation.
*
* @return array|null
* The properties to export or NULL if they can not be determine from the
* config entity type annotation.
*
* @throws \Drupal\Core\Config\Schema\SchemaIncompleteException
* Thrown when the configuration entity type does not have the annotation or
* a configuration schema.
* config entity type annotation or the schema.
*/
public function getPropertiesToExport($id = NULL);
......
......@@ -8,6 +8,7 @@
namespace Drupal\Tests\Core\Config\Entity;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Config\Schema\SchemaIncompleteException;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\Language;
......@@ -585,6 +586,17 @@ public function testThirdPartySettings() {
$this->assertEquals([$third_party], $this->entity->getThirdPartyProviders());
}
/**
* @covers ::toArray
*/
public function testToArraySchemaException() {
$this->entityType->expects($this->any())
->method('getPropertiesToExport')
->willReturn(NULL);
$this->setExpectedException(SchemaIncompleteException::class, 'Incomplete or missing schema for test_provider.');
$this->entity->toArray();
}
}
class TestConfigEntityWithPluginCollections extends ConfigEntityBaseWithPluginCollections {
......
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\Core\Config\Entity;
use Drupal\Core\Config\Schema\SchemaIncompleteException;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
......@@ -208,12 +207,11 @@ public function testGetPropertiesToExportSchemaFallback() {
/**
* @covers ::getPropertiesToExport
*/
public function testGetPropertiesToExportException() {
public function testGetPropertiesToExportNoFallback() {
$config_entity_type = new ConfigEntityType([
'id' => 'example_config_entity_type',
]);
$this->setExpectedException(SchemaIncompleteException::class);
$config_entity_type->getPropertiesToExport();
$this->assertNull($config_entity_type->getPropertiesToExport());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment