diff --git a/core/modules/comment/comment.post_update.php b/core/modules/comment/comment.post_update.php new file mode 100644 index 0000000..b1e721e --- /dev/null +++ b/core/modules/comment/comment.post_update.php @@ -0,0 +1,32 @@ +hasDefinition($comment_type->getTargetEntityTypeId())) { + $comment_type->save(); + } + }); +} + +/** + * @} End of "addtogroup updates-8.1.x". + */ diff --git a/core/modules/comment/src/Entity/CommentType.php b/core/modules/comment/src/Entity/CommentType.php index b31dc63..487cca0 100644 --- a/core/modules/comment/src/Entity/CommentType.php +++ b/core/modules/comment/src/Entity/CommentType.php @@ -93,4 +93,14 @@ public function getTargetEntityTypeId() { return $this->target_entity_type_id; } + /** + * {@inheritdoc} + */ + public function calculateDependencies() { + parent::calculateDependencies(); + $target_entity_type = \Drupal::entityTypeManager()->getDefinition($this->getTargetEntityTypeId()); + $this->addDependency('module', $target_entity_type->getProvider()); + return $this; + } + } diff --git a/core/modules/comment/src/Tests/CommentTypeTest.php b/core/modules/comment/src/Tests/CommentTypeTest.php index fb5028f..656ba2d 100644 --- a/core/modules/comment/src/Tests/CommentTypeTest.php +++ b/core/modules/comment/src/Tests/CommentTypeTest.php @@ -187,4 +187,15 @@ public function testCommentTypeDeletion() { $this->assertRaw(t('The comment type %label has been deleted.', array('%label' => $type->label()))); } + /** + * Tests that the provider of the target entity is listed as a dependency. + */ + public function testCalculateDependencies() { + // Create a comment type programmatically. + $comment_type = $this->createCommentType('dep_test'); + $target_entity_type = \Drupal::entityTypeManager()->getDefinition($comment_type->getTargetEntityTypeId()); + $dependencies = $comment_type->getDependencies() + ['module' => []]; + $this->assertTrue(in_array($target_entity_type->getProvider(), $dependencies['module'])); + } + } diff --git a/core/modules/comment/src/Tests/Update/CommentUpdateTest.php b/core/modules/comment/src/Tests/Update/CommentUpdateTest.php new file mode 100644 index 0000000..d62a64d --- /dev/null +++ b/core/modules/comment/src/Tests/Update/CommentUpdateTest.php @@ -0,0 +1,51 @@ +databaseDumpFiles = [ + __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.filled.standard.php.gz', + ]; + } + + /** + * Tests comment_post_update_provider_dependency(). + * + * @see comment_post_update_provider_dependency(). + */ + public function testPostUpdateCommentTypeDependencies() { + $default_comment_type = 'comment.type.comment'; + $forum_comment_type = 'comment.type.comment_forum'; + + // Check that default comment type doesn't depend on the node module. + $dependencies = $this->config($default_comment_type)->get('dependencies.module') ?: []; + $this->assertFalse(in_array('node', $dependencies)); + + // Check that forum comment type doesn't depend on the node module. + $dependencies = $this->config($forum_comment_type)->get('dependencies.module') ?: []; + $this->assertFalse(in_array('node', $dependencies)); + + $this->runUpdates(); + + // Check that default comment type does depend on the node module. + $dependencies = $this->config($default_comment_type)->get('dependencies.module') ?: []; + $this->assertTrue(in_array('node', $dependencies)); + + // Check that forum comment type does depend on the node module. + $dependencies = $this->config($forum_comment_type)->get('dependencies.module') ?: []; + $this->assertTrue(in_array('node', $dependencies)); + } + +} diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php index 65d0fb4..12fc44c 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php @@ -41,26 +41,32 @@ protected function setUp() { CommentType::create([ 'id' => 'comment_node_page', 'label' => $this->randomMachineName(), + 'target_entity_type_id' => 'node', ])->save(); CommentType::create([ 'id' => 'comment_node_article', 'label' => $this->randomMachineName(), + 'target_entity_type_id' => 'node', ])->save(); CommentType::create([ 'id' => 'comment_node_blog', 'label' => $this->randomMachineName(), + 'target_entity_type_id' => 'node', ])->save(); CommentType::create([ 'id' => 'comment_node_book', 'label' => $this->randomMachineName(), + 'target_entity_type_id' => 'node', ])->save(); CommentType::create([ 'id' => 'comment_node_forum', 'label' => $this->randomMachineName(), + 'target_entity_type_id' => 'node', ])->save(); CommentType::create([ 'id' => 'comment_node_test_content_type', 'label' => $this->randomMachineName(), + 'target_entity_type_id' => 'node', ])->save(); NodeType::create([ diff --git a/core/modules/forum/config/install/comment.type.comment_forum.yml b/core/modules/forum/config/install/comment.type.comment_forum.yml index 44a2d65..224982c 100644 --- a/core/modules/forum/config/install/comment.type.comment_forum.yml +++ b/core/modules/forum/config/install/comment.type.comment_forum.yml @@ -4,6 +4,8 @@ dependencies: enforced: module: - forum + module: + - node id: comment_forum label: Comment_forum target_entity_type_id: node diff --git a/core/profiles/standard/config/install/comment.type.comment.yml b/core/profiles/standard/config/install/comment.type.comment.yml index ddcbbc9..14af64c 100644 --- a/core/profiles/standard/config/install/comment.type.comment.yml +++ b/core/profiles/standard/config/install/comment.type.comment.yml @@ -1,6 +1,8 @@ langcode: en status: true -dependencies: { } +dependencies: + module: + - node id: comment label: 'Default comments' target_entity_type_id: node