Home

Adding Fields to Page Comments

What it Does

Adds an email field to page comments.

Requirements

This is based on and tested in Silverstripe 2.3.5 (I believe it will work as far back is 2.3.2, but this is untested)

This isn't as simple as it should be.  I am also sure that things could be done in a better way, please comment if you have improvments.

Override PageComments

You'll need to override the ContentController->PageComments() function.  This is essentially a copy and paste from sapphire/core/control/ContentController.php and change the reference to PageCommentInterface to PageCommentExtendedInterface, which you will create in the next step.
mysite/code/Page.php

Extending PageCommentInterface

PageCommentInterface is the Request Handler for page comments.  You will need to override the function PostCommentForm().  Unfortunately because of the way this function is written calling the parent on it and then adding the new fields is not possible (as far as I know), so you must copy the existing function from the parent class and then add your new field in the fields and then to load the new field from the session you'll also have to add your new field to the loadDataFrom array.  You are not done with this file yet, now you must also set the session for your new field.  To accomplish this you'll have to extend the internal class PageCommentInterface_Form and the function postComment().  In this case you can load up your session and then just call the parent function.  Don't forget to change the reference to PageCommentInterface_Form to your new class.
mysite/code/PageCommentExtendedInterface.php:

Setuping up your site configuration

You will be creating a decorator, you must include some code in your _config.php to assign it.  You will also be creating an extension to an Admin section you will want to add a rule to redirect the comments action to your new extension, also remove the old admin section.
mysite/_config.php:

(NOTE:  I tried to use LeftAndMainDecorator initially instead of extending CommentAdmin, but I ran into several issues)

Decorating PageComment

This could be as simple as just adding a new db static and pushing a new TextField onto CMSFields, however I took it a step further and set it up to send and email after someone posts a comment.  The email needs better formatting and it could use the admin email and the links to delete and mark as spam could be generated more dynamically.  This is not really part of the tutorial but I thought I would share.
mysite/code/PageCommentDecorator.php:

Extending CommentAdmin

And Finally, if you want to see the new data fields in the backend you'll have to extend the CommentAdmin and override EditForm(). Again, I had to copy and paste the function from the source due to the way it was written.  You must add the table field and the PopupFields for your new data field.
mysite/code/CommentAdminExtension:

That is it.  I'd apreciate any feedback you have as this is my first tutorial.  I'm considering packaging this as a module, it would also be my first module.  I feel the code needs to be a bit better for a module so if you have any improvements don't hesitate contacting me.

Special thanks to Mike Mannix for running through this and proving it works and is somewhat easy to follow, as well as fixing my horrible grammar.  Mike is working on his first Silverstripe site elmbrew.com, he completed the level one tutorials and then moved on to this.  It is a work in progress so keep an eye on it.

About the Author

Name: Dan Rye

Website: http://www.ryedesigns.com

Dan is a developer running a small Photography, Design, and Development Studio - Rye Designs with his wife Vicki.  Based in the Cincinnati, OH area, serving the tri-state area and beyond.  Dan is also a Software Engineer for MAG, developing offline manufacturing software for the aeronautics industry.

Comments (10)

  • <a href="http://www.guccis.net">gucci bags</a> <a href="http://www.guccis.net">gucci outlet</a> <a href="http://www.guccis.net">gucci handbags</a> <a href="http://www.guccis.net">gucci purses</a> <a href="http://www.chanels.cc">chanel purses</a>
    <a href="http://www.chanels.cc">chanel bags</a>
    <a href="http://www.chanels.cc">chanel handbags</a>
    <a href="http://www.chanels.cc/chanel-watches-c-111.html">chanel watches & chanel j12 watches</a>
    <a href="http://www.chanels.cc/chanel-sunglasses-c-110.html">chanel sunglasses & chanel sunglass</a>

    <a href="http://www.chanelsonline.com">chanel purses</a>
    <a href="http://www.chanelsonline.com">chanel bags</a>
    <a href="http://www.chanelsonline.com">chanel handbags</a><a href="http://www.monclerjacket2011.com">Moncler</a> <a href="http://www.monclerjacket2011.com">Moncler Jackets</a> <a href="http://www.monclerjacket2011.com">Monlcer Coats</a> <a href="http://www.monclerjacket2011.com/moncler-jackets-women-c-1.html">Moncler Jackets Women</a> <a href="http://www.monclerjacket2011.com/moncler-jackets-mens-c-2.html">Moncler Jackets Mens</a> <a href="http://www.monclerjacket2011.com/moncler-jackets-kids-c-3.html">Moncler Jackets Kids</a> <a href="http://www.monclerjacket2011.com/moncler-vest-women-c-4.html">Moncler Vest women</a> <a href="http://www.monclerjacket2011.com/moncler-vest-men-c-5.html">Moncler Vest Men</a> <a href="http://www.monclerjacket2011.com/moncler-boots-c-6.html">Moncler Boots</a> <a href="http://www.monclerjacket2011.com/moncler-bags-c-7.html">Moncler Bags</a> <a href="http://www.monclerjacket2011.com/moncler-tshirts-c-8.html">Moncler T-shirts</a> <a href="http://www.monclerjacket2011.com/moncler-scarf-c-9.html">Moncler Scarf</a> <a href="http://www.monclerjacket2011.com">Moncler Jackets 2010</a>
    <a href="http://www.uselv.com">louis vuitton bags</a>
    <a href="http://www.uselv.com">louis vuitton handbags</a>
    <a href="http://www.uselv.com">louis vuitton</a>
    <a href="http://www.uselv.com">lv</a>


    Posted by chanel bags, 29/09/2010 2:27am (4 years ago)

  • I wish you have a wonderful day!
    jiemo

    Posted by Gucci, 28/09/2010 3:12am (4 years ago)

  • I wish you have a wonderful day!
    jiemo

    Posted by Chanel, 28/09/2010 3:12am (4 years ago)

  • I wish you have a wonderful day!
    jiemo

    Posted by coach , 28/09/2010 3:11am (4 years ago)

  • I wish you have a wonderful day!
    jiemo

    Posted by Louis Vuitton, 28/09/2010 3:10am (4 years ago)

  • I wish you have a wonderful day!
    jiemo

    Posted by nike, 28/09/2010 3:00am (4 years ago)

  • [url=http://www.edhardyhive.com]replica ed hardy clothes[/url]
    [url=http://www.edhardyhive.com]urban gucci shoes[/url]
    [url=http://www.edhardyhive.com]true religion on sale[/url]
    [url=http://www.edhardyhive.com]retail abercrombie fitch[/url]
    [url=http://www.edhardyhive.com]new armani watches[/url]
    [url=http://www.edhardyhive.com]discount coogi jeans[/url]
    [url=http://www.edhardyhive.com]fashion prada handbags[/url]
    [url=http://www.edhardyhive.com]louis vuitton new[/url]
    [url=http://www.edhardyhive.com]chanel wallets wholesale[/url]
    [url=http://www.edhardyhive.com]juicy couture cheap[/url]

    Posted by chanel wallets , 27/09/2010 9:06pm (4 years ago)

  • http://http://www.findsoso.com/

    Our website wholesale for many kinds of fashion clothing, such
    as nike,jordan,prama,****, we also sell jeans,shirts,bags,hat and
    many kinds of tiffany. All the products are free shipping, and the
    the price is enticement , and also can accept the paypal
    payment.we can ship within 24 hours after your payment.

    accept the paypal

    free shipping

    competitive price

    any size available



    Everything is here http://www.findsoso.com friends, please
    enjoy viewing bar

    Thanks

    Posted by xihuan, 27/09/2010 10:25am (4 years ago)

  • You are not done with this file yet, now you must also set the session for your new field. To accomplish this you'll have to extend the internal class PageCommentInterface_Form and the function postComment().

    Posted by Diabetic Supplies, 27/09/2010 1:14am (4 years ago)

  • Nice info I just gone through your some posts including this one. You are illustrating things in very simple and lucid manner.

    Posted by infographic, 23/09/2010 4:42am (4 years ago)

1 2 3 4 next »

RSS feed for comments on this page RSS feed for all comments

Post your comment

Comments have been disabled. Please visit this post on SSBits.com to post your comment