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/CommentTypeForm.php b/core/modules/comment/src/CommentTypeForm.php index 8e73652..1f2cb34 100644 --- a/core/modules/comment/src/CommentTypeForm.php +++ b/core/modules/comment/src/CommentTypeForm.php @@ -35,12 +35,20 @@ class CommentTypeForm extends EntityForm { protected $logger; /** + * The comment manager. + * + * @var \Drupal\comment\CommentManagerInterface + */ + protected $commentManager; + + /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('entity.manager'), - $container->get('logger.factory')->get('comment') + $container->get('logger.factory')->get('comment'), + $container->get('comment.manager') ); } @@ -51,10 +59,13 @@ public static function create(ContainerInterface $container) { * The entity manager service. * @param \Psr\Log\LoggerInterface $logger * A logger instance. + * @param \Drupal\comment\CommentManagerInterface $comment_manager + * The comment manager. */ - public function __construct(EntityManagerInterface $entity_manager, LoggerInterface $logger) { + public function __construct(EntityManagerInterface $entity_manager, LoggerInterface $logger, CommentManagerInterface $comment_manager) { $this->entityManager = $entity_manager; $this->logger = $logger; + $this->commentManager = $comment_manager; } /** @@ -156,6 +167,7 @@ public function save(array $form, FormStateInterface $form_state) { $this->logger->notice('Comment type %label has been updated.', array('%label' => $comment_type->label(), 'link' => $edit_link)); } else { + $this->commentManager->addBodyField($comment_type->id()); drupal_set_message(t('Comment type %label has been added.', array('%label' => $comment_type->label()))); $this->logger->notice('Comment type %label has been added.', array('%label' => $comment_type->label(), 'link' => $edit_link)); } diff --git a/core/modules/comment/src/Entity/CommentType.php b/core/modules/comment/src/Entity/CommentType.php index 3a1b3a8..8c36b22 100644 --- a/core/modules/comment/src/Entity/CommentType.php +++ b/core/modules/comment/src/Entity/CommentType.php @@ -92,14 +92,4 @@ public function getTargetEntityTypeId() { return $this->target_entity_type_id; } - /** - * {@inheritdoc} - */ - public function postSave(EntityStorageInterface $storage, $update = TRUE) { - parent::postSave($storage, $update); - if (!$update && !$this->isSyncing()) { - \Drupal::service('comment.manager')->addBodyField($this->id()); - } - } - } 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/CommentPreviewTest.php b/core/modules/comment/src/Tests/CommentPreviewTest.php index 8d188c3..b5b089a 100644 --- a/core/modules/comment/src/Tests/CommentPreviewTest.php +++ b/core/modules/comment/src/Tests/CommentPreviewTest.php @@ -28,6 +28,48 @@ class CommentPreviewTest extends CommentTestBase { protected $profile = 'standard'; /** + * @todo remove setUp() once https://www.drupal.org/node/2321385 lands. + */ + protected function setUp() { + parent::setUp(); + $entity_type = 'node'; + $bundle = 'article'; + $field_name = 'comment'; + // Assign widget settings for the 'default' form mode. + entity_get_form_display($entity_type, $bundle, 'default') + ->setComponent($field_name, array( + 'type' => 'comment_default', + 'weight' => 20, + )) + ->save(); + + // The comment field should be hidden in all other form displays. + foreach (\Drupal::entityManager()->getFormModes($entity_type) as $id => $form_mode) { + $display = entity_get_form_display($entity_type, $bundle, $id); + // Only update existing displays. + if ($display && !$display->isNew()) { + $display->removeComponent($field_name)->save(); + } + } + // Set default to display comment list. + entity_get_display($entity_type, $bundle, 'default') + ->setComponent($field_name, array( + 'label' => 'above', + 'type' => 'comment_default', + 'weight' => 20, + )) + ->save(); + // The comment field should be hidden in all other view displays. + foreach (\Drupal::entityManager()->getViewModes($entity_type) as $id => $view_mode) { + $display = entity_get_display($entity_type, $bundle, $id); + // Only update existing displays. + if ($display && !$display->isNew()) { + $display->removeComponent($field_name)->save(); + } + } + } + + /** * Tests comment preview. */ function testCommentPreview() { 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/CommentTypeTest.php b/core/modules/comment/src/Tests/CommentTypeTest.php index 4a6d1b1..5801a96 100644 --- a/core/modules/comment/src/Tests/CommentTypeTest.php +++ b/core/modules/comment/src/Tests/CommentTypeTest.php @@ -109,14 +109,14 @@ public function testCommentTypeEditing() { $this->assertRaw('Bar', 'New name was displayed.'); $this->clickLink('Manage fields'); $this->assertUrl(\Drupal::url('field_ui.overview_comment', array('comment_type' => 'comment'), array('absolute' => TRUE)), [], 'Original machine name was used in URL.'); - + $this->assertTrue($this->cssSelect('tr#comment-body'), 'Body field exists.'); // Remove the body field. $this->drupalPostForm('admin/structure/comment/manage/comment/fields/comment.comment.comment_body/delete', array(), t('Delete')); // Resave the settings for this type. $this->drupalPostForm('admin/structure/comment/manage/comment', array(), t('Save')); // Check that the body field doesn't exist. $this->drupalGet('admin/structure/comment/manage/comment/fields'); - $this->assertNoRaw('comment_body', 'Body field was not found.'); + $this->assertFalse($this->cssSelect('tr#comment-body'), 'Body field does not exist.'); } /** 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/forum/config/install/comment.type.comment_forum.yml b/core/modules/forum/config/install/comment.type.comment_forum.yml new file mode 100644 index 0000000..fed6de3 --- /dev/null +++ b/core/modules/forum/config/install/comment.type.comment_forum.yml @@ -0,0 +1,7 @@ +langcode: en +status: true +dependencies: { } +id: comment_forum +label: Comment_forum +target_entity_type_id: node +description: 'Default comment field' diff --git a/core/modules/forum/config/install/core.entity_form_display.comment.comment_forum.default.yml b/core/modules/forum/config/install/core.entity_form_display.comment.comment_forum.default.yml new file mode 100644 index 0000000..85a0393 --- /dev/null +++ b/core/modules/forum/config/install/core.entity_form_display.comment.comment_forum.default.yml @@ -0,0 +1,31 @@ +langcode: en +status: true +dependencies: + config: + - comment.type.comment_forum + - field.field.comment.comment_forum.comment_body + module: + - text +id: comment.comment_forum.default +targetEntityType: comment +bundle: comment_forum +mode: default +content: + author: + weight: -2 + subject: + type: string_textfield + weight: 10 + settings: + size: 60 + placeholder: '' + third_party_settings: { } + comment_body: + type: text_textarea + weight: 11 + settings: + rows: 5 + placeholder: '' + third_party_settings: { } +hidden: { } +third_party_settings: { } diff --git a/core/modules/forum/config/install/core.entity_view_display.comment.comment_forum.default.yml b/core/modules/forum/config/install/core.entity_view_display.comment.comment_forum.default.yml new file mode 100644 index 0000000..065906f --- /dev/null +++ b/core/modules/forum/config/install/core.entity_view_display.comment.comment_forum.default.yml @@ -0,0 +1,24 @@ +langcode: en +status: true +dependencies: + config: + - comment.type.comment_forum + - field.field.comment.comment_forum.comment_body + module: + - text +id: comment.comment_forum.default +label: null +targetEntityType: comment +bundle: comment_forum +mode: default +content: + comment_body: + label: hidden + type: text_default + weight: 0 + settings: { } + third_party_settings: { } + links: + weight: 100 +hidden: { } +third_party_settings: { } diff --git a/core/modules/forum/config/install/field.field.comment.comment_forum.comment_body.yml b/core/modules/forum/config/install/field.field.comment.comment_forum.comment_body.yml new file mode 100644 index 0000000..d0b6472 --- /dev/null +++ b/core/modules/forum/config/install/field.field.comment.comment_forum.comment_body.yml @@ -0,0 +1,21 @@ +langcode: en +status: true +dependencies: + config: + - comment.type.comment_forum + - field.storage.comment.comment_body + module: + - text +id: comment.comment_forum.comment_body +field_name: comment_body +entity_type: comment +bundle: comment_forum +label: Comment +description: '' +required: true +translatable: true +default_value: { } +default_value_callback: '' +settings: { } +third_party_settings: { } +field_type: text_long diff --git a/core/modules/forum/config/install/field.field.node.forum.comment_forum.yml b/core/modules/forum/config/install/field.field.node.forum.comment_forum.yml new file mode 100644 index 0000000..6153e72 --- /dev/null +++ b/core/modules/forum/config/install/field.field.node.forum.comment_forum.yml @@ -0,0 +1,33 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.node.comment_forum + - node.type.forum + module: + - comment +id: node.forum.comment_forum +field_name: comment_forum +entity_type: node +bundle: forum +label: Comments +description: '' +required: true +translatable: true +default_value: + - + status: 2 + cid: 0 + last_comment_name: null + last_comment_timestamp: 0 + last_comment_uid: 0 + comment_count: 0 +default_value_callback: '' +settings: + default_mode: 0 + per_page: 50 + form_location: true + anonymous: 0 + preview: 1 +third_party_settings: { } +field_type: comment diff --git a/core/modules/forum/config/install/field.storage.node.comment_forum.yml b/core/modules/forum/config/install/field.storage.node.comment_forum.yml new file mode 100644 index 0000000..d5d3b96 --- /dev/null +++ b/core/modules/forum/config/install/field.storage.node.comment_forum.yml @@ -0,0 +1,18 @@ +langcode: en +status: true +dependencies: + module: + - comment + - node +id: node.comment_forum +field_name: comment_forum +entity_type: node +type: comment +settings: + comment_type: comment_forum +module: comment +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index 6605c1d..1bd294d 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -81,29 +81,15 @@ function forum_install() { )) ->save(); } - // Add the comment field to the forum node type. - $field_storages = entity_load_multiple_by_properties('field_storage_config', array( - 'type' => 'comment', - 'field_name' => 'comment_forum', - 'include_deleted' => FALSE, - )); - if (empty($field_storages)) { - Drupal::service('comment.manager')->addDefaultField('node', 'forum', 'comment_forum', CommentItemInterface::OPEN, 'comment_forum'); - - // Add here because we don't have param in addDefaultField function. - $field = FieldConfig::loadByName('node', 'forum', 'comment_forum'); - $field->settings['default_mode'] = CommentManagerInterface::COMMENT_MODE_FLAT; - $field->save(); - - // Hide label for comment field. - entity_get_display('node', 'forum', 'default') - ->setComponent('comment_forum', array( - 'label' => 'hidden', - 'type' => 'comment_default', - 'weight' => 20, - )) - ->save(); - } + // @todo remove once https://www.drupal.org/node/2321385 lands. + // Hide label for comment field. + entity_get_display('node', 'forum', 'default') + ->setComponent('comment_forum', array( + 'label' => 'hidden', + 'type' => 'comment_default', + 'weight' => 20, + )) + ->save(); } } 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/migrate_drupal/src/Tests/d6/MigrateCommentTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php index 8206618..ccfb661 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php @@ -39,6 +39,10 @@ protected function setUp() { 'target_entity_type_id' => 'node', ))->save(); + $commentManager = $this->container->get('comment.manager'); + $commentManager->addBodyField('comment'); + $commentManager->addBodyField('comment_no_subject'); + $node = entity_create('node', array( 'type' => 'story', 'nid' => 1, diff --git a/core/modules/rdf/src/Tests/StandardProfileTest.php b/core/modules/rdf/src/Tests/StandardProfileTest.php index 29e9804..f6f3320 100644 --- a/core/modules/rdf/src/Tests/StandardProfileTest.php +++ b/core/modules/rdf/src/Tests/StandardProfileTest.php @@ -104,6 +104,44 @@ class StandardProfileTest extends WebTestBase { protected function setUp() { parent::setUp(); + // @todo remove once https://www.drupal.org/node/2321385 lands. + $entity_type = 'node'; + $bundle = 'article'; + $field_name = 'comment'; + // Assign widget settings for the 'default' form mode. + entity_get_form_display($entity_type, $bundle, 'default') + ->setComponent($field_name, array( + 'type' => 'comment_default', + 'weight' => 20, + )) + ->save(); + + // The comment field should be hidden in all other form displays. + foreach (\Drupal::entityManager()->getFormModes($entity_type) as $id => $form_mode) { + $display = entity_get_form_display($entity_type, $bundle, $id); + // Only update existing displays. + if ($display && !$display->isNew()) { + $display->removeComponent($field_name)->save(); + } + } + // Set default to display comment list. + entity_get_display($entity_type, $bundle, 'default') + ->setComponent($field_name, array( + 'label' => 'above', + 'type' => 'comment_default', + 'weight' => 20, + )) + ->save(); + // The comment field should be hidden in all other view displays. + foreach (\Drupal::entityManager()->getViewModes($entity_type) as $id => $view_mode) { + $display = entity_get_display($entity_type, $bundle, $id); + // Only update existing displays. + if ($display && !$display->isNew()) { + $display->removeComponent($field_name)->save(); + } + } + // end @todo + $this->base_uri = \Drupal::url('', [], ['absolute' => TRUE]); // Create two test users. 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; } } diff --git a/core/modules/user/src/Tests/UserPictureTest.php b/core/modules/user/src/Tests/UserPictureTest.php index 639c382..8ee3ff6 100644 --- a/core/modules/user/src/Tests/UserPictureTest.php +++ b/core/modules/user/src/Tests/UserPictureTest.php @@ -39,6 +39,43 @@ protected function setUp() { 'post comments', 'skip comment approval', )); + // @todo remove once https://www.drupal.org/node/2321385 lands. + $entity_type = 'node'; + $bundle = 'article'; + $field_name = 'comment'; + // Assign widget settings for the 'default' form mode. + entity_get_form_display($entity_type, $bundle, 'default') + ->setComponent($field_name, array( + 'type' => 'comment_default', + 'weight' => 20, + )) + ->save(); + + // The comment field should be hidden in all other form displays. + foreach (\Drupal::entityManager()->getFormModes($entity_type) as $id => $form_mode) { + $display = entity_get_form_display($entity_type, $bundle, $id); + // Only update existing displays. + if ($display && !$display->isNew()) { + $display->removeComponent($field_name)->save(); + } + } + // Set default to display comment list. + entity_get_display($entity_type, $bundle, 'default') + ->setComponent($field_name, array( + 'label' => 'above', + 'type' => 'comment_default', + 'weight' => 20, + )) + ->save(); + // The comment field should be hidden in all other view displays. + foreach (\Drupal::entityManager()->getViewModes($entity_type) as $id => $view_mode) { + $display = entity_get_display($entity_type, $bundle, $id); + // Only update existing displays. + if ($display && !$display->isNew()) { + $display->removeComponent($field_name)->save(); + } + } + // end @todo } /** diff --git a/core/profiles/standard/config/install/core.entity_form_display.comment.comment.default.yml b/core/profiles/standard/config/install/core.entity_form_display.comment.comment.default.yml new file mode 100644 index 0000000..51a97b1 --- /dev/null +++ b/core/profiles/standard/config/install/core.entity_form_display.comment.comment.default.yml @@ -0,0 +1,31 @@ +langcode: en +status: true +dependencies: + config: + - comment.type.comment + - field.field.comment.comment.comment_body + module: + - text +id: comment.comment.default +targetEntityType: comment +bundle: comment +mode: default +content: + author: + weight: -2 + subject: + type: string_textfield + weight: 10 + settings: + size: 60 + placeholder: '' + third_party_settings: { } + comment_body: + type: text_textarea + weight: 11 + settings: + rows: 5 + placeholder: '' + third_party_settings: { } +hidden: { } +third_party_settings: { } diff --git a/core/profiles/standard/config/install/core.entity_view_display.comment.comment.default.yml b/core/profiles/standard/config/install/core.entity_view_display.comment.comment.default.yml new file mode 100644 index 0000000..83f69ce --- /dev/null +++ b/core/profiles/standard/config/install/core.entity_view_display.comment.comment.default.yml @@ -0,0 +1,24 @@ +langcode: en +status: true +dependencies: + config: + - comment.type.comment + - field.field.comment.comment.comment_body + module: + - text +id: comment.comment.default +label: null +targetEntityType: comment +bundle: comment +mode: default +content: + comment_body: + label: hidden + type: text_default + weight: 0 + settings: { } + third_party_settings: { } + links: + weight: 100 +hidden: { } +third_party_settings: { } diff --git a/core/profiles/standard/config/install/field.field.comment.comment.comment_body.yml b/core/profiles/standard/config/install/field.field.comment.comment.comment_body.yml new file mode 100644 index 0000000..30aaabe --- /dev/null +++ b/core/profiles/standard/config/install/field.field.comment.comment.comment_body.yml @@ -0,0 +1,21 @@ +langcode: en +status: true +dependencies: + config: + - comment.type.comment + - field.storage.comment.comment_body + module: + - text +id: comment.comment.comment_body +field_name: comment_body +entity_type: comment +bundle: comment +label: Comment +description: '' +required: true +translatable: true +default_value: { } +default_value_callback: '' +settings: { } +third_party_settings: { } +field_type: text_long diff --git a/core/profiles/standard/config/install/field.field.node.article.comment.yml b/core/profiles/standard/config/install/field.field.node.article.comment.yml new file mode 100644 index 0000000..932daff --- /dev/null +++ b/core/profiles/standard/config/install/field.field.node.article.comment.yml @@ -0,0 +1,33 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.node.comment + - node.type.article + module: + - comment +id: node.article.comment +field_name: comment +entity_type: node +bundle: article +label: Comments +description: '' +required: true +translatable: true +default_value: + - + status: 2 + cid: 0 + last_comment_name: null + last_comment_timestamp: 0 + last_comment_uid: 0 + comment_count: 0 +default_value_callback: '' +settings: + default_mode: 1 + per_page: 50 + form_location: true + anonymous: 0 + preview: 1 +third_party_settings: { } +field_type: comment diff --git a/core/profiles/standard/config/install/field.storage.node.comment.yml b/core/profiles/standard/config/install/field.storage.node.comment.yml new file mode 100644 index 0000000..4713148 --- /dev/null +++ b/core/profiles/standard/config/install/field.storage.node.comment.yml @@ -0,0 +1,18 @@ +langcode: en +status: true +dependencies: + module: + - comment + - node +id: node.comment +field_name: comment +entity_type: node +type: comment +settings: + comment_type: comment +module: comment +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false diff --git a/core/profiles/standard/config/install/rdf.mapping.comment.node__comment.yml b/core/profiles/standard/config/install/rdf.mapping.comment.comment.yml similarity index 92% rename from core/profiles/standard/config/install/rdf.mapping.comment.node__comment.yml rename to core/profiles/standard/config/install/rdf.mapping.comment.comment.yml index 268eb80..7eedd97 100644 --- a/core/profiles/standard/config/install/rdf.mapping.comment.node__comment.yml +++ b/core/profiles/standard/config/install/rdf.mapping.comment.comment.yml @@ -1,3 +1,10 @@ +langcode: und +status: true +dependencies: + config: + - comment.type.comment + module: + - comment id: comment.comment targetEntityType: comment bundle: comment @@ -23,9 +30,4 @@ fieldMappings: uid: properties: - 'schema:author' - mapping_type: 'rel' -dependencies: - module: - - comment - config: - - comment.type.comment + mapping_type: rel diff --git a/core/profiles/standard/src/Tests/StandardTest.php b/core/profiles/standard/src/Tests/StandardTest.php index 3ba2347..8892c8b 100644 --- a/core/profiles/standard/src/Tests/StandardTest.php +++ b/core/profiles/standard/src/Tests/StandardTest.php @@ -23,6 +23,48 @@ class StandardTest extends WebTestBase { protected $profile = 'standard'; /** + * @todo remove setUp() once https://www.drupal.org/node/2321385 lands. + */ + protected function setUp() { + parent::setUp(); + $entity_type = 'node'; + $bundle = 'article'; + $field_name = 'comment'; + // Assign widget settings for the 'default' form mode. + entity_get_form_display($entity_type, $bundle, 'default') + ->setComponent($field_name, array( + 'type' => 'comment_default', + 'weight' => 20, + )) + ->save(); + + // The comment field should be hidden in all other form displays. + foreach (\Drupal::entityManager()->getFormModes($entity_type) as $id => $form_mode) { + $display = entity_get_form_display($entity_type, $bundle, $id); + // Only update existing displays. + if ($display && !$display->isNew()) { + $display->removeComponent($field_name)->save(); + } + } + // Set default to display comment list. + entity_get_display($entity_type, $bundle, 'default') + ->setComponent($field_name, array( + 'label' => 'above', + 'type' => 'comment_default', + 'weight' => 20, + )) + ->save(); + // The comment field should be hidden in all other view displays. + foreach (\Drupal::entityManager()->getViewModes($entity_type) as $id => $view_mode) { + $display = entity_get_display($entity_type, $bundle, $id); + // Only update existing displays. + if ($display && !$display->isNew()) { + $display->removeComponent($field_name)->save(); + } + } + } + + /** * Tests Standard installation profile. */ function testStandard() { diff --git a/core/profiles/standard/standard.install b/core/profiles/standard/standard.install index c2b5582..cf4769d 100644 --- a/core/profiles/standard/standard.install +++ b/core/profiles/standard/standard.install @@ -23,9 +23,7 @@ function standard_install() { // Set front page to "node". \Drupal::config('system.site')->set('page.front', 'node')->save(); - // Add comment field to article node type. - \Drupal::service('comment.manager')->addDefaultField('node', 'article', 'comment', CommentItemInterface::OPEN); - + // @todo remove once https://www.drupal.org/node/2321385 lands. // Hide the comment field in the rss view mode. entity_get_display('node', 'article', 'rss') ->removeComponent('comment')