diff --git a/core/config/schema/core.data_types.schema.yml b/core/config/schema/core.data_types.schema.yml index 4968087..354d282 100644 --- a/core/config/schema/core.data_types.schema.yml +++ b/core/config/schema/core.data_types.schema.yml @@ -400,10 +400,12 @@ field_config_base: core.base_field_override.*.*.*: type: field_config_base + config_entity_type: base_field_override label: 'Base field bundle override' core.date_format.*: type: config_entity + config_entity_type: date_format label: 'Date format' mapping: id: diff --git a/core/config/schema/core.entity.schema.yml b/core/config/schema/core.entity.schema.yml index 90813e5..e4dbfae 100644 --- a/core/config/schema/core.entity.schema.yml +++ b/core/config/schema/core.entity.schema.yml @@ -2,6 +2,7 @@ core.entity_view_mode.*.*: type: config_entity + config_entity_type: entity_view_mode label: 'Entity view mode settings' mapping: id: @@ -19,6 +20,7 @@ core.entity_view_mode.*.*: core.entity_form_mode.*.*: type: config_entity + config_entity_type: entity_form_mode label: 'Entity form mode settings' mapping: id: @@ -37,6 +39,7 @@ core.entity_form_mode.*.*: # Overview configuration information for view mode or form mode displays. core.entity_view_display.*.*.*: type: config_entity + config_entity_type: entity_view_display label: 'Entity display' mapping: id: @@ -85,6 +88,7 @@ core.entity_view_display.*.*.*: # Overview configuration information for form mode displays. core.entity_form_display.*.*.*: type: config_entity + config_entity_type: entity_form_display label: 'Entity form display' mapping: id: diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 453c18d..fd0bbf7 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -274,7 +274,7 @@ public function toArray() { /** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type */ $entity_type = $this->getEntityType(); - $properties_to_export = $entity_type->getPropertiesToExport($this->id()); + $properties_to_export = $entity_type->getPropertiesToExport(); $id_key = $entity_type->getKey('id'); foreach ($properties_to_export as $property_name => $export_name) { diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php index e0c1881..7e8734d 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php @@ -187,10 +187,9 @@ public function getPropertiesToExport() { } } else { - $config_name = $this->getConfigPrefix() . '.*'; - $definition = $this->getTypedConfig()->getDefinition($config_name); + $definition = $this->getTypedConfig()->getDefinitionForEntityType($this->id()); if (!isset($definition['mapping'])) { - throw new SchemaIncompleteException(SafeMarkup::format('Incomplete or missing schema for @config_name', ['@config_name' => $config_name])); + throw new SchemaIncompleteException(SafeMarkup::format('Incomplete or missing schema for @entity_type_id', ['@entity_type_id' => $this->id()])); } $this->mergedConfigExport = array_combine(array_keys($definition['mapping']), array_keys($definition['mapping'])); } diff --git a/core/lib/Drupal/Core/Config/TypedConfigManager.php b/core/lib/Drupal/Core/Config/TypedConfigManager.php index 42756d6..12f1849 100644 --- a/core/lib/Drupal/Core/Config/TypedConfigManager.php +++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php @@ -159,6 +159,20 @@ public function getDefinition($base_plugin_id, $exception_on_invalid = TRUE, $is /** * {@inheritdoc} */ + public function getDefinitionForEntityType($entity_type_id) { + $id = 'undefined'; + foreach ($this->getDefinitions() as $definition_id => $definition) { + if (isset($definition['config_entity_type']) && $definition['config_entity_type'] === $entity_type_id) { + $id = $definition_id; + break; + } + } + return $this->getDefinition($id); + } + + /** + * {@inheritdoc} + */ public function clearCachedDefinitions() { $this->schemaStorage->reset(); parent::clearCachedDefinitions(); diff --git a/core/lib/Drupal/Core/Config/TypedConfigManagerInterface.php b/core/lib/Drupal/Core/Config/TypedConfigManagerInterface.php index e9e562e..7aa1d33 100644 --- a/core/lib/Drupal/Core/Config/TypedConfigManagerInterface.php +++ b/core/lib/Drupal/Core/Config/TypedConfigManagerInterface.php @@ -122,4 +122,17 @@ public function hasConfigSchema($name); */ public function getDefinition($plugin_id, $exception_on_invalid = TRUE, $is_config_name = FALSE); + /** + * Gets the plugin definition for a specific entity type. + * + * @param string $entity_type_id + * The unique identifier of the entity type. + * + * @return array + * A plugin definition array. If the given entity type ID does not have + * typed configuration definition assigned, the definition of an undefined + * element type is returned. + */ + public function getDefinitionForEntityType($entity_type_id); + } diff --git a/core/modules/block/config/schema/block.schema.yml b/core/modules/block/config/schema/block.schema.yml index 16d79bc..619ca1a 100644 --- a/core/modules/block/config/schema/block.schema.yml +++ b/core/modules/block/config/schema/block.schema.yml @@ -2,6 +2,7 @@ block.block.*: type: config_entity + config_entity_type: block label: 'Block' mapping: id: diff --git a/core/modules/block_content/config/schema/block_content.schema.yml b/core/modules/block_content/config/schema/block_content.schema.yml index 2e7c338..b50cf97 100644 --- a/core/modules/block_content/config/schema/block_content.schema.yml +++ b/core/modules/block_content/config/schema/block_content.schema.yml @@ -2,6 +2,7 @@ block_content.type.*: type: config_entity + config_entity_type: block_content label: 'Custom block type settings' mapping: id: diff --git a/core/modules/comment/config/schema/comment.schema.yml b/core/modules/comment/config/schema/comment.schema.yml index d9f5a77..37b9445 100644 --- a/core/modules/comment/config/schema/comment.schema.yml +++ b/core/modules/comment/config/schema/comment.schema.yml @@ -37,6 +37,7 @@ action.configuration.comment_unpublish_action: comment.type.*: type: config_entity + config_entity_type: comment_type label: 'Comment type settings' mapping: id: diff --git a/core/modules/config/tests/config_test/config/schema/config_test.schema.yml b/core/modules/config/tests/config_test/config/schema/config_test.schema.yml index 6cad91b..c00a3be 100644 --- a/core/modules/config/tests/config_test/config/schema/config_test.schema.yml +++ b/core/modules/config/tests/config_test/config/schema/config_test.schema.yml @@ -2,6 +2,7 @@ config_test_dynamic: type: config_entity + config_entity_type: config_test mapping: id: type: string @@ -35,6 +36,7 @@ config_test.dynamic.*.*: config_test.query.*: type: config_entity + config_entity_type: config_query_test mapping: id: type: string diff --git a/core/modules/contact/config/schema/contact.schema.yml b/core/modules/contact/config/schema/contact.schema.yml index 5a62e9d..52b17e3 100644 --- a/core/modules/contact/config/schema/contact.schema.yml +++ b/core/modules/contact/config/schema/contact.schema.yml @@ -2,6 +2,7 @@ contact.form.*: type: config_entity + config_entity_type: contact_form label: 'Contact form' mapping: id: diff --git a/core/modules/editor/config/schema/editor.schema.yml b/core/modules/editor/config/schema/editor.schema.yml index 80a01f9..7a19628 100644 --- a/core/modules/editor/config/schema/editor.schema.yml +++ b/core/modules/editor/config/schema/editor.schema.yml @@ -2,6 +2,7 @@ editor.editor.*: type: config_entity + config_entity_type: editor label: 'Text editor' mapping: format: diff --git a/core/modules/field/config/schema/field.schema.yml b/core/modules/field/config/schema/field.schema.yml index 55760a7..440abea 100644 --- a/core/modules/field/config/schema/field.schema.yml +++ b/core/modules/field/config/schema/field.schema.yml @@ -10,6 +10,7 @@ field.settings: field.storage.*.*: type: config_entity + config_entity_type: field_storage_config label: 'Field' mapping: id: @@ -53,4 +54,5 @@ field.storage.*.*: field.field.*.*.*: type: field_config_base + config_entity_type: field_config label: 'Field' diff --git a/core/modules/filter/config/schema/filter.schema.yml b/core/modules/filter/config/schema/filter.schema.yml index b45a475..8e184d2 100644 --- a/core/modules/filter/config/schema/filter.schema.yml +++ b/core/modules/filter/config/schema/filter.schema.yml @@ -13,6 +13,7 @@ filter.settings: filter.format.*: type: config_entity + config_entity_type: filter_format label: 'Text formats' mapping: name: diff --git a/core/modules/image/config/schema/image.schema.yml b/core/modules/image/config/schema/image.schema.yml index 4949fa3..d26fd12 100644 --- a/core/modules/image/config/schema/image.schema.yml +++ b/core/modules/image/config/schema/image.schema.yml @@ -2,6 +2,7 @@ image.style.*: type: config_entity + config_entity_type: image_style label: 'Image style' mapping: name: diff --git a/core/modules/language/config/schema/language.schema.yml b/core/modules/language/config/schema/language.schema.yml index 5e3f55b..767d47b 100644 --- a/core/modules/language/config/schema/language.schema.yml +++ b/core/modules/language/config/schema/language.schema.yml @@ -86,6 +86,7 @@ language.mappings: language.entity.*: type: config_entity + config_entity_type: configurable_language label: 'Language' mapping: id: @@ -106,6 +107,7 @@ language.entity.*: language.content_settings.*.*: type: config_entity + config_entity_type: language_content_settings label: 'Content Language Settings' mapping: id: diff --git a/core/modules/migrate/config/schema/migrate.schema.yml b/core/modules/migrate/config/schema/migrate.schema.yml index c48bdd1..4e39577 100644 --- a/core/modules/migrate/config/schema/migrate.schema.yml +++ b/core/modules/migrate/config/schema/migrate.schema.yml @@ -2,6 +2,7 @@ migrate.migration.*: type: config_entity + config_entity_type: migration label: 'Migration' mapping: id: diff --git a/core/modules/node/config/schema/node.schema.yml b/core/modules/node/config/schema/node.schema.yml index dbc8ac9..5fb8fdc 100644 --- a/core/modules/node/config/schema/node.schema.yml +++ b/core/modules/node/config/schema/node.schema.yml @@ -10,6 +10,7 @@ node.settings: node.type.*: type: config_entity + config_entity_type: node_type label: 'Content type' mapping: name: diff --git a/core/modules/rdf/config/schema/rdf.schema.yml b/core/modules/rdf/config/schema/rdf.schema.yml index a331382..27d8869 100644 --- a/core/modules/rdf/config/schema/rdf.schema.yml +++ b/core/modules/rdf/config/schema/rdf.schema.yml @@ -2,6 +2,7 @@ rdf.mapping.*.*: type: config_entity + config_entity_type: rdf_mapping label: 'RDF mapping' mapping: id: diff --git a/core/modules/responsive_image/config/schema/responsive_image.schema.yml b/core/modules/responsive_image/config/schema/responsive_image.schema.yml index f05a8e2..f4d9ec8 100644 --- a/core/modules/responsive_image/config/schema/responsive_image.schema.yml +++ b/core/modules/responsive_image/config/schema/responsive_image.schema.yml @@ -2,6 +2,7 @@ responsive_image.styles.*: type: config_entity + config_entity_type: responsive_image_style label: 'Responsive image style' mapping: id: diff --git a/core/modules/search/config/schema/search.schema.yml b/core/modules/search/config/schema/search.schema.yml index 2ed4c09..916186e 100644 --- a/core/modules/search/config/schema/search.schema.yml +++ b/core/modules/search/config/schema/search.schema.yml @@ -69,6 +69,7 @@ search.settings: search.page.*: type: config_entity + config_entity_type: search_page label: 'Search page' mapping: id: diff --git a/core/modules/shortcut/config/schema/shortcut.schema.yml b/core/modules/shortcut/config/schema/shortcut.schema.yml index 7d9420b..6d9b338 100644 --- a/core/modules/shortcut/config/schema/shortcut.schema.yml +++ b/core/modules/shortcut/config/schema/shortcut.schema.yml @@ -2,6 +2,7 @@ shortcut.set.*: type: config_entity + config_entity_type: shortcut_set label: 'Shortcut settings' mapping: id: diff --git a/core/modules/system/config/schema/system.schema.yml b/core/modules/system/config/schema/system.schema.yml index 7cde50d..5da1d6a 100644 --- a/core/modules/system/config/schema/system.schema.yml +++ b/core/modules/system/config/schema/system.schema.yml @@ -242,6 +242,7 @@ system.theme: system.menu.*: type: config_entity + config_entity_type: menu label: 'Menu' mapping: id: @@ -259,6 +260,7 @@ system.menu.*: system.action.*: type: config_entity + config_entity_type: action label: 'System action' mapping: id: diff --git a/core/modules/taxonomy/config/schema/taxonomy.schema.yml b/core/modules/taxonomy/config/schema/taxonomy.schema.yml index efa08e1..81d3ce6 100644 --- a/core/modules/taxonomy/config/schema/taxonomy.schema.yml +++ b/core/modules/taxonomy/config/schema/taxonomy.schema.yml @@ -16,6 +16,7 @@ taxonomy.settings: taxonomy.vocabulary.*: type: config_entity + config_entity_type: vocabulary label: 'Vocabulary' mapping: name: diff --git a/core/modules/tour/config/schema/tour.schema.yml b/core/modules/tour/config/schema/tour.schema.yml index caf7363..299d83e 100644 --- a/core/modules/tour/config/schema/tour.schema.yml +++ b/core/modules/tour/config/schema/tour.schema.yml @@ -2,6 +2,7 @@ tour.tour.*: type: config_entity + config_entity_type: tour label: 'Tour settings' mapping: id: diff --git a/core/modules/user/config/schema/user.schema.yml b/core/modules/user/config/schema/user.schema.yml index 627d8a6..6e57fb8 100644 --- a/core/modules/user/config/schema/user.schema.yml +++ b/core/modules/user/config/schema/user.schema.yml @@ -105,6 +105,7 @@ user.flood: user.role.*: type: config_entity + config_entity_type: role label: 'User role settings' mapping: id: diff --git a/core/modules/views/config/schema/views.schema.yml b/core/modules/views/config/schema/views.schema.yml index 7ea599d..97403ee 100644 --- a/core/modules/views/config/schema/views.schema.yml +++ b/core/modules/views/config/schema/views.schema.yml @@ -67,6 +67,7 @@ views.settings: views.view.*: type: config_entity + config_entity_type: view label: 'View' mapping: id: diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index c4413eb..8707671 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -90,13 +90,6 @@ class ConfigEntityStorageTest extends UnitTestCase { protected $cacheTagsInvalidator; /** - * The mocked typed config manager. - * - * @var \Drupal\Core\Config\TypedConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected $typedConfigManager; - - /** * The configuration manager. * * @var \Drupal\Core\Config\ConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject @@ -132,6 +125,13 @@ protected function setUp() { $this->entityType->expects($this->any()) ->method('getListCacheTags') ->willReturn(array('test_entity_type_list')); + $this->entityType->expects($this->any()) + ->method('getPropertiesToExport') + ->willReturn([ + 'id' => 'id', + 'uuid' => 'uuid', + 'dependencies' => 'dependencies', + ]); $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); @@ -163,16 +163,10 @@ protected function setUp() { $this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface'); - $this->typedConfigManager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface'); - $this->typedConfigManager->expects($this->any()) - ->method('getDefinition') - ->will($this->returnValue(array('mapping' => array('id' => '', 'uuid' => '', 'dependencies' => '')))); - $this->configManager = $this->getMock('Drupal\Core\Config\ConfigManagerInterface'); $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); - $container->set('config.typed', $this->typedConfigManager); $container->set('cache_tags.invalidator', $this->cacheTagsInvalidator); $container->set('config.manager', $this->configManager); $container->set('language_manager', $this->languageManager); diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php index 5bf1c70..1aea2f7 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php @@ -187,15 +187,10 @@ public function providerGetPropertiesToExport() { * @covers ::getPropertiesToExport */ public function testGetPropertiesToExportFromSchema() { - $definition = [ - 'id' => 'my_config_entity_type', - 'provider' => 'my_module', - ]; - $typed_config_manager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface'); $typed_config_manager->expects($this->once()) - ->method('getDefinition') - ->with($definition['provider'] . '.' . $definition['id'] . '.*') + ->method('getDefinitionForEntityType') + ->with('example_config_entity_type') ->willReturn(['mapping' => ['id' => '', 'dependencies' => '']]); $container = new ContainerBuilder(); $container->set('config.typed', $typed_config_manager); @@ -205,7 +200,7 @@ public function testGetPropertiesToExportFromSchema() { 'id' => 'id', 'dependencies' => 'dependencies', ]; - $entity_type = $this->setUpConfigEntityType($definition); + $entity_type = $this->setUpConfigEntityType([]); $properties_to_export = $entity_type->getPropertiesToExport(); $this->assertSame($expected, $properties_to_export); @@ -219,20 +214,19 @@ public function testGetPropertiesToExportFromSchema() { * @covers ::getPropertiesToExport * * @expectedException \Drupal\Core\Config\Schema\SchemaIncompleteException - * @expectedExceptionMessage Incomplete or missing schema for my_module.example_config_entity_type.* + * @expectedExceptionMessage Incomplete or missing schema for example_config_entity_type */ public function testGetPropertiesToExportFromMissingSchema() { $typed_config_manager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface'); $typed_config_manager->expects($this->once()) - ->method('getDefinition') + ->method('getDefinitionForEntityType') ->willReturn([]); $container = new ContainerBuilder(); $container->set('config.typed', $typed_config_manager); \Drupal::setContainer($container); - $definition = ['provider' => 'my_module']; $expected = []; - $entity_type = $this->setUpConfigEntityType($definition); + $entity_type = $this->setUpConfigEntityType([]); $properties_to_export = $entity_type->getPropertiesToExport(); $this->assertSame($expected, $properties_to_export); diff --git a/core/tests/Drupal/Tests/Core/Config/TypedConfigManagerTest.php b/core/tests/Drupal/Tests/Core/Config/TypedConfigManagerTest.php new file mode 100644 index 0000000..71a091d --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Config/TypedConfigManagerTest.php @@ -0,0 +1,76 @@ + [ + 'label' => 'Undefined', + 'class' => '\Drupal\Core\Config\Schema\Undefined', + ], + 'core.valid.*' => [ + 'label' => 'Valid', + 'config_entity_type' => 'valid', + ], + 'core.invalid.*' => [ + 'label' => 'invalid', + ], + ]; + + $manager = $this->getMockBuilder('\Drupal\Core\Config\TypedConfigManager') + ->disableOriginalConstructor() + ->setMethods(['getDefinitions']) + ->getMock(); + $manager->expects($this->any()) + ->method('getDefinitions') + ->willReturn($definitions); + + $definition = $manager->getDefinitionForEntityType($entity_type_id); + $this->assertSame($expected, $definition); + } + + /** + * Provides test data for testGetDefinitionForEntityType(). + */ + public function providerTestGetDefinitionForEntityType() { + $data = []; + $data[] = [ + 'valid', + [ + 'label' => 'Valid', + 'config_entity_type' => 'valid', + 'definition_class' => '\Drupal\Core\TypedData\DataDefinition', + 'type' => 'core.valid.*', + ], + ]; + $data[] = [ + 'invalid', + [ + 'label' => 'Undefined', + 'class' => '\Drupal\Core\Config\Schema\Undefined', + 'definition_class' => '\Drupal\Core\TypedData\DataDefinition', + 'type' => 'undefined', + ], + ]; + return $data; + } + +}