diff --git a/core/modules/comment/config/install/field.storage.comment.comment_body.yml b/core/modules/comment/config/install/field.storage.comment.comment_body.yml new file mode 100644 index 0000000..8cd88d8 --- /dev/null +++ b/core/modules/comment/config/install/field.storage.comment.comment_body.yml @@ -0,0 +1,17 @@ +langcode: en +status: true +dependencies: + module: + - comment + - text +id: comment.comment_body +field_name: comment_body +entity_type: comment +type: text_long +settings: { } +module: text +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: true diff --git a/core/modules/comment/src/CommentManager.php b/core/modules/comment/src/CommentManager.php index 0094a01..db5cd4e 100644 --- a/core/modules/comment/src/CommentManager.php +++ b/core/modules/comment/src/CommentManager.php @@ -217,24 +217,13 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment', * {@inheritdoc} */ public function addBodyField($comment_type_id) { - // Create the field if needed. - $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); - if (!$field_storage) { - $field_storage = $this->entityManager->getStorage('field_storage_config')->create(array( - 'field_name' => 'comment_body', - 'type' => 'text_long', - 'entity_type' => 'comment', - )); - $field_storage->save(); - } if (!FieldConfig::loadByName('comment', $comment_type_id, 'comment_body')) { // Attaches the body field by default. $field = $this->entityManager->getStorage('field_config')->create(array( - 'field_name' => 'comment_body', 'label' => 'Comment', - 'entity_type' => 'comment', 'bundle' => $comment_type_id, 'required' => TRUE, + 'field_storage' => FieldStorageConfig::loadByName('comment', 'comment_body'), )); $field->save(); diff --git a/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php b/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php index 8747737f2d..8373964 100644 --- a/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php +++ b/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php @@ -40,7 +40,6 @@ protected function setUp() { // Install tables and config needed to render comments. $this->installSchema('comment', array('comment_entity_statistics')); - $this->installEntitySchema('comment'); $this->installConfig(array('system', 'filter')); // Comment rendering generates links, so build the router. diff --git a/core/modules/comment/src/Tests/CommentFieldAccessTest.php b/core/modules/comment/src/Tests/CommentFieldAccessTest.php index ebeada1..83354fe 100644 --- a/core/modules/comment/src/Tests/CommentFieldAccessTest.php +++ b/core/modules/comment/src/Tests/CommentFieldAccessTest.php @@ -78,7 +78,6 @@ class CommentFieldAccessTest extends EntityUnitTestBase { protected function setUp() { parent::setUp(); $this->installConfig(array('user')); - $this->installEntitySchema('comment'); $this->installSchema('comment', array('comment_entity_statistics')); } diff --git a/core/modules/comment/src/Tests/CommentFieldsTest.php b/core/modules/comment/src/Tests/CommentFieldsTest.php index bec1f5a..3d8fcb5 100644 --- a/core/modules/comment/src/Tests/CommentFieldsTest.php +++ b/core/modules/comment/src/Tests/CommentFieldsTest.php @@ -40,9 +40,10 @@ function testCommentDefaultFields() { $field->delete(); - // Check that the 'comment_body' field is deleted. + // Check that the 'comment_body' field is not deleted since it is persisted + // even if it has no fields. $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); - $this->assertTrue(empty($field_storage), 'The comment_body field was deleted'); + $this->assertTrue($field_storage, 'The comment_body field storage was not deleted'); // Create a new content type. $type_name = 'test_node_type_2'; diff --git a/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php b/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php index a81b949..24e933e 100644 --- a/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php +++ b/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php @@ -36,6 +36,8 @@ protected function setUp() { parent::setUp(); $this->installEntitySchema('comment'); $this->installSchema('comment', array('comment_entity_statistics')); + // Create the comment body field storage. + $this->installConfig(array('field')); } /** diff --git a/core/modules/comment/src/Tests/CommentValidationTest.php b/core/modules/comment/src/Tests/CommentValidationTest.php index c22e15b..f468ec9 100644 --- a/core/modules/comment/src/Tests/CommentValidationTest.php +++ b/core/modules/comment/src/Tests/CommentValidationTest.php @@ -29,7 +29,6 @@ class CommentValidationTest extends EntityUnitTestBase { */ protected function setUp() { parent::setUp(); - $this->installEntitySchema('comment'); $this->installSchema('comment', array('comment_entity_statistics')); } diff --git a/core/modules/hal/src/Tests/EntityTest.php b/core/modules/hal/src/Tests/EntityTest.php index a115146..91d917c 100644 --- a/core/modules/hal/src/Tests/EntityTest.php +++ b/core/modules/hal/src/Tests/EntityTest.php @@ -30,7 +30,6 @@ protected function setUp() { \Drupal::service('router.builder')->rebuild(); $this->installSchema('system', array('sequences')); $this->installSchema('comment', array('comment_entity_statistics')); - $this->installEntitySchema('comment'); $this->installEntitySchema('taxonomy_term'); } diff --git a/core/modules/hal/src/Tests/NormalizerTestBase.php b/core/modules/hal/src/Tests/NormalizerTestBase.php index 2fef044..e933c43 100644 --- a/core/modules/hal/src/Tests/NormalizerTestBase.php +++ b/core/modules/hal/src/Tests/NormalizerTestBase.php @@ -64,19 +64,22 @@ protected function setUp() { $this->installSchema('system', array('url_alias', 'router')); $this->installEntitySchema('user'); $this->installEntitySchema('entity_test'); - // If the concrete test sub-class installs node.module, ensure that the node - // entity schema is created before the field configurations are installed, - // because the node entity tables need to be created before the body field - // storage tables. This prevents trying to create the body field tables - // twice. + // If the concrete test sub-class installs the Node or Comment modules, + // ensure that the node and comment entity schema are created before the + // field configurations are installed. This is because the entity tables + // need to be created before the body field storage tables. This prevents + // trying to create the body field tables twice. $class = get_class($this); while ($class) { if (property_exists($class, 'modules')) { // Only check the modules, if the $modules property was not inherited. $rp = new \ReflectionProperty($class, 'modules'); if ($rp->class == $class) { - if (in_array('node', $class::$modules, TRUE)) { - $this->installEntitySchema('node'); + $entity_schema_to_install = array_intersect(array('node', 'comment'), $class::$modules); + if (!empty($entity_schema_to_install)) { + foreach($entity_schema_to_install as $module) { + $this->installEntitySchema($module); + } break; } } diff --git a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php index 537697f..3e040a4 100644 --- a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php @@ -44,8 +44,6 @@ class EntityCrudHookTest extends EntityUnitTestBase { protected function setUp() { parent::setUp(); - $this->installEntitySchema('comment'); - $this->installSchema('user', array('users_data')); $this->installSchema('file', array('file_usage')); $this->installSchema('node', array('node_access')); diff --git a/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php b/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php index 22537ba..b321646 100644 --- a/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php +++ b/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php @@ -47,19 +47,22 @@ protected function setUp() { $this->installEntitySchema('user'); $this->installEntitySchema('entity_test'); - // If the concrete test sub-class installs node.module, ensure that the node - // entity schema is created before the field configurations are installed, - // because the node entity tables need to be created before the body field - // storage tables. This prevents trying to create the body field tables - // twice. + // If the concrete test sub-class installs the Node or Comment modules, + // ensure that the node and comment entity schema are created before the + // field configurations are installed. This is because the entity tables + // need to be created before the body field storage tables. This prevents + // trying to create the body field tables twice. $class = get_class($this); while ($class) { if (property_exists($class, 'modules')) { // Only check the modules, if the $modules property was not inherited. $rp = new \ReflectionProperty($class, 'modules'); if ($rp->class == $class) { - if (in_array('node', $class::$modules, TRUE)) { - $this->installEntitySchema('node'); + $entity_schema_to_install = array_intersect(array('node', 'comment'), $class::$modules); + if (!empty($entity_schema_to_install)) { + foreach($entity_schema_to_install as $module) { + $this->installEntitySchema($module); + } break; } }