From dc1f8622e0144852554f1be0f6a405676708c1ed Mon Sep 17 00:00:00 2001 From: Dylan Wagstaff Date: Fri, 11 Jan 2019 11:48:51 +1300 Subject: [PATCH] FIX show name of members in summary tables Anonymous comments (posted by the public at large) must have a name and an email address associated with them. On the other hand, a logged in user will have the `Member` record details used for this information, via the Author relationship. However the summary fields do not allow for this, and only reference Name and Email on the Comment model directly, so any comment posted by a logged in member has no data for name and email displayed in the various GridFields in the CMS for administering comments (either per page, or in the global ModelAdmin). To recitfy this we can change the summary fields to use getter methods that will return the Comment model info, or fall back to the Author associated Member record if Name and Email are unset on the Comment. --- src/Model/Comment.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Model/Comment.php b/src/Model/Comment.php index 0dd6eec6..59ea8c7d 100755 --- a/src/Model/Comment.php +++ b/src/Model/Comment.php @@ -125,8 +125,8 @@ class Comment extends DataObject * {@inheritDoc} */ private static $summary_fields = array( - 'Name' => 'Submitted By', - 'Email' => 'Email', + 'getAuthorName' => 'Submitted By', + 'getAuthorEmail' => 'Email', 'Comment.LimitWordCount' => 'Comment', 'Created' => 'Date Posted', 'Parent.Title' => 'Post', @@ -450,6 +450,20 @@ public function getAuthorName() } } + /** + * Return the comment authors email address + * + * @return string + */ + public function getAuthorEmail() + { + if ($this->Email) { + return $this->Email; + } elseif ($author = $this->Author()) { + return $author->Email; + } + } + /** * Generate a secure admin-action link authorised for the specified member *