diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index a5e5f15..b689af3 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -61,7 +61,6 @@ public function form(array $form, array &$form_state, EntityInterface $comment) if ($is_admin) { $author = $comment->name->value; $status = (isset($comment->status->value) ? $comment->status->value : COMMENT_NOT_PUBLISHED); - $date = (!empty($comment->date) ? $comment->date : new DrupalDateTime($comment->created->value)); } else { if ($user->uid) { @@ -71,8 +70,12 @@ public function form(array $form, array &$form_state, EntityInterface $comment) $author = ($comment->name->value ? $comment->name->value : ''); } $status = (user_access('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED); - $date = ''; } + $date = ''; + if (!empty($comment->cid)) { + $date = (!empty($comment->date) ? $comment->date : format_date($comment->created, 'custom', 'Y-m-d H:i O')); + } + // Add the author name field depending on the current user. $form['author']['name'] = array( diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php index faf6ace..8d5405d 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php @@ -80,7 +80,7 @@ function testCommentPreview() { */ function testCommentEditPreviewSave() { $langcode = LANGUAGE_NOT_SPECIFIED; - $web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval')); + $web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval', 'edit own comments')); $this->drupalLogin($this->admin_user); $this->setCommentPreview(DRUPAL_OPTIONAL); $this->setCommentForm(TRUE); @@ -142,6 +142,15 @@ function testCommentEditPreviewSave() { $this->assertEqual($comment_loaded->comment_body->value, $edit['comment_body[' . $langcode . '][0][value]'], 'Comment body loaded.'); $this->assertEqual($comment_loaded->name->value, $edit['name'], 'Name loaded.'); $this->assertEqual($comment_loaded->created->value, $raw_date, 'Date loaded.'); + // Check that the date and time of the comment are correct when edited. + $this->drupalLogout(); + $user_edit = array(); + $user_edit['subject'] = $this->randomName(8); + $this->drupalLogin($web_user); + $this->drupalPost('comment/' . $comment->id . '/edit', $user_edit, t('Save')); + $this->drupalGet('node/' . $this->node->nid); + $this->assertText($expected_text_date, 'Expected date and time for comment edited.'); + $this->drupalLogout(); }