diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index ecbe5b2..50e7caf 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -110,7 +110,6 @@ public function form(array $form, array &$form_state) { if ($is_admin) { $author = $comment->name->value; $status = (isset($comment->status->value) ? $comment->status->value : COMMENT_NOT_PUBLISHED); - $date = (!empty($comment->date) ? $comment->date : DrupalDateTime::createFromTimestamp($comment->created->value)); if (empty($form_state['comment_preview'])) { $form['#title'] = $this->t('Edit comment %title', array( '%title' => $comment->subject->value, @@ -125,7 +124,11 @@ public function form(array $form, array &$form_state) { $author = ($comment->name->value ? $comment->name->value : ''); } $status = ($this->currentUser->hasPermission('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED); - $date = ''; + } + + $date = ''; + if ($comment->id()) { + $date = !empty($comment->date) ? $comment->date : DrupalDateTime::createFromTimestamp($comment->created->value); } // 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 f940c4a..387c2a3 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php @@ -102,7 +102,7 @@ function testCommentPreview() { * Tests comment edit, preview, and save. */ function testCommentEditPreviewSave() { - $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); @@ -164,6 +164,17 @@ function testCommentEditPreviewSave() { $this->assertEqual($comment_loaded->comment_body->value, $edit['comment_body[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.'); + $this->drupalLogout(); + + // Check that the date and time of the comment are correct when edited by + // non-admin users. + $user_edit = array(); + $expected_created_time = $comment_loaded->created->value; + $this->drupalLogin($web_user); + $this->drupalPostForm('comment/' . $comment->id() . '/edit', $user_edit, t('Save')); + $comment_loaded = comment_load($comment->id(), TRUE); + $this->assertEqual($comment_loaded->created->value, $expected_created_time, 'Expected date and time for comment edited.'); + $this->drupalLogout(); } }