Well, I've done some searching, and tried to create my own sublass of PageComment and PageCommentInterface but I'm really not having any luck!
I've found threads that touch on the subject, but what I've tried so far just plain isn't working...
[link]http://silverstripe.org/template-questions/show/251237[/link]
[link]http://silverstripe.org/archive/show/7489[/link]
[link]http://silverstripe.org/archive/show/247213[/link]
There are some more threads too, but nothing definitive.
It seems that extending PageComment and PageCommentInterface is like opening a huge can of worms.
This is what I've tried so far:
Extending PageComment to include the new CommenterEmail field:
class PageCommentPlus extends PageComment
{
static $db = array(
"CommenterEmail" => "Text"
);
}
Extending PageCommentInterface plus _Form to handle (or at least I thought) the new field:
class PageCommentPlusInterface extends PageCommentInterface
{
function forTemplate()
{
return $this->renderWith('PageCommentPlusInterface');
}
function PostCommentForm()
{
...
// optional commenter URL
$fields->push(new TextField("CommenterURL", _t('PageCommentInterface.COMMENTERURL', "Your website URL")));
$fields->push(new TextField("CommenterEmail", "Your email address"));
...
}
function Comments()
{
...
$comments = DataObject::get("PageCommentPlus", "ParentID = '" . Convert::raw2sql($this->page->ID) . "' $spamfilter $unmoderatedfilter", "Created DESC", "", $limit);
...
}
}
class PageCommentPlusInterface_Form extends PageCommentInterface_Form
{
function postcomment($data) {
...
$comment = Object::create('PageCommentPlus');
...
}
}
Altering my Page class to accommodate the new PageCommentPlus class:
class Page extends SiteTree
{
...
public static $has_many = array(
'Comments' => 'PageCommentPlus'
);
...
}
class Page_Controller extends ContentController
{
/**
* Returns a page comment system
*/
function PageComments()
{
if($this->data() && $this->data()->ProvideComments) {
return new PageCommentPlusInterface($this, 'PageComments', $this->data());
} else {
if(isset($_REQUEST['executeForm']) && $_REQUEST['executeForm'] == 'PageComments.PostCommentForm') {
echo "Comments have been disabled for this page";
die();
}
}
}
}
I've rebuilt and cleared the old comments out, but now my comment form isn't even showing up...
Has anybody got a nice complete code example of how to successfully add an email field to the comments system? If they could just explain the main steps I'd be vary, very grateful!
Thank you in advance :)
Edit: I edited this down cos this post was pretty huge!