diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index cead0cd..9bb28a8 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -63,7 +63,6 @@ public function form(array $form, array &$form_state, EntityInterface $comment) if ($is_admin) { $author = (!$comment->uid && $comment->name ? $comment->name : $comment->registered_name); $status = (isset($comment->status) ? $comment->status : COMMENT_NOT_PUBLISHED); - $date = (!empty($comment->date) ? $comment->date : format_date($comment->created, 'custom', 'Y-m-d H:i O')); } else { if ($user->uid) { @@ -73,7 +72,10 @@ public function form(array $form, array &$form_state, EntityInterface $comment) $author = ($comment->name ? $comment->name : ''); } $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. diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php index e9e197a..da1ea92 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php @@ -71,7 +71,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); @@ -128,6 +128,16 @@ function testCommentEditPreviewSave() { $this->assertEqual($comment_loaded->name, $edit['name'], 'Name loaded.'); $this->assertEqual($comment_loaded->created, $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(); + } }