From f772d32d55604e77cb7a916c1870de3162d25064 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Wed, 22 Apr 2015 17:00:28 +1200 Subject: [PATCH] API Add readonly parent details in comment form in CMS --- code/model/Comment.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/code/model/Comment.php b/code/model/Comment.php index be75c9e..d23d89e 100755 --- a/code/model/Comment.php +++ b/code/model/Comment.php @@ -561,6 +561,43 @@ class Comment extends DataObject { ); } + // Show parent comment if given + if(($parent = $this->ParentComment()) && $parent->exists()) { + $fields->push(new HeaderField( + 'ParentComment_Title', + _t('Comment.ParentComment_Title', 'This comment is a reply to the below') + )); + // Created date + $fields->push( + $parent + ->obj('Created') + ->scaffoldFormField($parent->fieldLabel('Created')) + ->setName('ParentComment_Created') + ->setValue($parent->Created) + ->performReadonlyTransformation() + ); + + // Name (could be member or string value) + $fields->push( + $parent + ->obj('AuthorName') + ->scaffoldFormField($parent->fieldLabel('AuthorName')) + ->setName('ParentComment_AuthorName') + ->setValue($parent->getAuthorName()) + ->performReadonlyTransformation() + ); + + // Comment body + $fields->push( + $parent + ->obj('EscapedComment') + ->scaffoldFormField($parent->fieldLabel('Comment')) + ->setName('ParentComment_EscapedComment') + ->setValue($parent->Comment) + ->performReadonlyTransformation() + ); + } + $this->extend('updateCMSFields', $fields); return $fields; }