22 December, 2009

Customizing the comments forms in SilverStripe

I came across some development stuff this week. I had to install a SilverStripe blog, yet the client needed some customizations for the Page Comments, also to change the form with which you can comment.

I always like to extend the core codes of SilverStripe but not to change them as it always helps when updating the CMS + the Framework.

Anyway this is what I did about the commenting, I had to extend the PageCommentInterface.php, I created a new child class of PageCommentInterface, called CustomPageCommentsInterface ( this is in ./mysite/code/CustomPageCommentsInterface.php ).

There I only had to override the method PostCommentForm.

This method creates a form, adds and Spam protection modules, MathSpamProtection, and the needed fields. Okay now I did one thing, I wanted to hide the Name and the URL fields of the comments. what I did is that I replaced them with hidden fields, and by the time it creates the form I assigned values to it by retrieving the logged in users details.

One more thing, for my requirement I didnt need any new fields to be introduced to comments, if you need any you can add them by a DataObjectDecorator, and create your field as you need.

Hope this information will be useful.

No comments: