commit 886fc5ef113d7936637475ecde97d1da4bcc2d69 Author: Lee Rowlands Date: Tue Nov 17 09:49:53 2015 +1000 p20 diff --git a/core/modules/comment/src/CommentStorage.php b/core/modules/comment/src/CommentStorage.php index 099e5f4..4f4efb0 100644 --- a/core/modules/comment/src/CommentStorage.php +++ b/core/modules/comment/src/CommentStorage.php @@ -337,4 +337,16 @@ public function getUnapprovedCount() { ->fetchField(); } + /** + * {@inheritdoc} + */ + protected function doPreSave(EntityInterface $entity) { + /* @var \Drupal\comment\CommentInterface $entity */ + if (!$entity->getOwner()->isAnonymous()) { + $entity->set('name', NULL); + $entity->set('mail', NULL); + } + return parent::doPreSave($entity); + } + } diff --git a/core/modules/comment/src/Tests/CommentInterfaceTest.php b/core/modules/comment/src/Tests/CommentInterfaceTest.php index b81494e..9893e85 100644 --- a/core/modules/comment/src/Tests/CommentInterfaceTest.php +++ b/core/modules/comment/src/Tests/CommentInterfaceTest.php @@ -230,7 +230,7 @@ public function testCommentEdit() { // Create a comment and make sure it is stored correctly. $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE); $this->assertTrue($this->commentExists($comment), 'Comment found.'); - $this->assertNull($comment->get('name'), 'Comment author name stored in database is NULL for registered user.'); + $this->assertNull($comment->get('name')->value, 'Comment author name stored in database is NULL for registered user.'); $this->assertEqual($comment->getAuthorName(), $this->adminUser->getAccountName(), 'Comment author name returned by API is current user.'); $this->assertEqual($comment->getOwnerId(), $this->adminUser->id(), 'Comment owner is current user.');