Comment form extender documentation updated.

svn path=/plone.app.discussion/trunk/; revision=50078
This commit is contained in:
Timo Stollenwerk 2011-05-28 11:11:58 +00:00
parent 7a7a708fc0
commit 1e331d957f
2 changed files with 37 additions and 20 deletions

View File

@ -1,29 +1,43 @@
====================================================
Howto extend the comment form with additional fields
====================================================
This document explains how to extend the plone.app.discussion comment form with
additional fields in an add-on product.
.. seealso::
* See the github collective for the source code of this howto:
https://github.com/collective/collective.example.commentextender/
plone.app.discussion uses the
`plone.z3cform.fieldsets <http://pypi.python.org/pypi/plone.z3cform#fieldsets-and-form-extenders>`_
package which provides support for modifications via "extender" adapters. The
idea is that a third party component can modify the fields in a form and the
way that they are grouped and ordered.
.. note::
This howto applies only to plone.app.discussion >= 2.0.4 and >= 1.1.1. Prior
versions will not store the extended fields on the comment.
.. seealso::
The source code of this howto can be found here:
https://github.com/collective/collective.example.commentextender/
Howto extend the comment form with an additional "website" field
================================================================
First, create a new plone package::
$ paster create -t plone my.commentextender
$ paster create -t plone example.commentextender
Go to the main directory of the package (my.commentextender/my/commentextender)
and create a new file commentextender.py containing the ICommentExtenderFields
interface definition with an additional "website" field, a persistent
CommentExtenderFields class to actually store the "website" value, a
CommentExtenderFactory to create the CommentExtenderFields, and CommentExtender
class to actually extend the default comment form with the field::
Go to the main directory of the package
(example.commentextender/example/commentextender) and create a new file
*commentextender.py*.
This file contains the ICommentExtenderFields interface definition with a
"website" field, a persistent CommentExtenderFields class to store the value of
the "website" field, a CommentExtenderFactory to create the
CommentExtenderFields, and a CommentExtender class to extend the default
comment form with the "website" field::
from persistent import Persistent
@ -79,8 +93,8 @@ class to actually extend the default comment form with the field::
hide, and reorder fields:
http://pypi.python.org/pypi/plone.z3cform#fieldsets-and-form-extenders
Now register the CommentExtenderFactory and CommentExtender Classes we just
created by adding the following lines to your configure.zcml::
Now register the CommentExtenderFactory and CommentExtender Classes that has
been created by adding the following lines to your configure.zcml::
<adapter
factory=".commentextender.CommentExtenderFactory"
@ -98,15 +112,17 @@ Since we do not only want to store the "website" value on the comments, but also
to show these values for existing comments, we have to override the comments
viewlet. The easiest way to do this is to use z3c.jbot.
First, add z3c.jbot to the setup.py of the my.commentextender package::
First, add `z3c.jbot <http://pypi.python.org/pypi/z3c.jbot>`_. to the setup.py
of the example.commentextender package::
install_requires=[
...
'z3c.jbot',
],
Next, create a new directory called "overrides" inside the my.commentextender
package and register it together with z3c.jbot in your configure.zcml::
Next, create a new directory called "overrides" inside the
example.commentextender package and register it together with z3c.jbot in your
configure.zcml::
<configure
...
@ -137,5 +153,5 @@ You can now add code to show the website attribute to the documentByLine::
</div>
</div>
Restart your Plone instance and you will see the "website" field in the
documentByLine next to the comments.

View File

@ -1,7 +1,8 @@
======
Howtos
======
.. toctree::
:maxdepth: 2
:maxdepth: 1
howto_extend_the_comment_form.txt