Last time I was able to finish things up with registering and deregistering the add-on in the plone site, so that when ever I activate my add-on from the ZMI on plone instance, it registered the default profile of my add-on, also it register the browserlayer of the add-on. So this things goes well and also there were some issues related to the versions which have been solved lately.
What's Next ?
After the registration of add-on we need to create a view on plone site so that when ever we click on the add-on we can get some page and configure our add-on from plone site. There are default configuration for the transform script already there and we can customize the configuration. So for that we have to create a control panel for our add-on so that user can get a platform to customize the configuration.
There were 2 ways to create a control panel :-
1) Either to overwrite the old cntrol panel of PortalTransform safe_html.
2) Or to create a separate control panel for our new safe_html add-on.
I choose the 2nd way to create a control panel and created a separate control panel for the add-on.
How to create a control panel in plone add-on ?
For creating control panel in plone add-on we have to
1) Create a schema for control pane.
2) register the control panel schema.
3) Create permissions for registering control panel.
Lets start with 1st step,
Create a Schema for control panel
We will create the schema for the control panel in a file, where we will define FilterTagSchema which will contain space for nasty tags, stripped tags and custom tags. Similarly we will create IFilterAttributeSchema, IFilterEditorSchema and Finally in IFilterSchema we will include all the above mentioned classes. After that we will create FilterControlPanelForm which will allow the above defined schema on the plone site.
Here is the snippet for FIlterControlForm :-
class FilterControlPanelForm(controlpanel.RegistryEditForm):
id = "FilterControlPanel"
label = _("SAFE HTML Filter settings")
description = _("Plone filters HTML tags that are considered security "
"risks. Be aware of the implications before making "
"changes below. By default only tags defined in XHTML "
"are permitted. In particular, to allow 'embed' as a tag "
"you must both remove it from 'Nasty tags' and add it to "
"'Custom tags'. Although the form will update "
"immediately to show any changes you make, your changes "
"are not saved until you press the 'Save' button.")
form_name = _("HTML Filter settings")
schema = IFilterSchema
schema_prefix = "plone"
def updateFields(self):
super(FilterControlPanelForm, self).updateFields()
Observer here we used schema for the filter control form as IFilterSchema which further includes all the classes as mentioned above.
Now finally we will wrap the control panel form and this will help us to get our control panel on plone site.
Register the Control panel
This was just the first step, but now after defining the control panel we have to register the control panel in the configuration.zcml in the generic way.
Here is the snippet of code done to register the control panel :-
Here we have registered the browser page with the name safe_html_transfrom-settings, for IPloneSiteRoot of CMFPlone and using our own add-on browser layer and importing our controlpanel class.
Adding permissions for control panel
We will notice that we have added the permissions at the end of the setup and for that we will create a separate file named permissions.zcml and import that file in the configuartion.zcml.
The permission.zcml file looks like this :-
What's Next ?
After the registration of add-on we need to create a view on plone site so that when ever we click on the add-on we can get some page and configure our add-on from plone site. There are default configuration for the transform script already there and we can customize the configuration. So for that we have to create a control panel for our add-on so that user can get a platform to customize the configuration.
There were 2 ways to create a control panel :-
1) Either to overwrite the old cntrol panel of PortalTransform safe_html.
2) Or to create a separate control panel for our new safe_html add-on.
I choose the 2nd way to create a control panel and created a separate control panel for the add-on.
How to create a control panel in plone add-on ?
For creating control panel in plone add-on we have to
1) Create a schema for control pane.
2) register the control panel schema.
3) Create permissions for registering control panel.
Lets start with 1st step,
Create a Schema for control panel
We will create the schema for the control panel in a file, where we will define FilterTagSchema which will contain space for nasty tags, stripped tags and custom tags. Similarly we will create IFilterAttributeSchema, IFilterEditorSchema and Finally in IFilterSchema we will include all the above mentioned classes. After that we will create FilterControlPanelForm which will allow the above defined schema on the plone site.
Here is the snippet for FIlterControlForm :-
class FilterControlPanelForm(controlpanel.RegistryEditForm):
id = "FilterControlPanel"
label = _("SAFE HTML Filter settings")
description = _("Plone filters HTML tags that are considered security "
"risks. Be aware of the implications before making "
"changes below. By default only tags defined in XHTML "
"are permitted. In particular, to allow 'embed' as a tag "
"you must both remove it from 'Nasty tags' and add it to "
"'Custom tags'. Although the form will update "
"immediately to show any changes you make, your changes "
"are not saved until you press the 'Save' button.")
form_name = _("HTML Filter settings")
schema = IFilterSchema
schema_prefix = "plone"
def updateFields(self):
super(FilterControlPanelForm, self).updateFields()
Observer here we used schema for the filter control form as IFilterSchema which further includes all the classes as mentioned above.
Now finally we will wrap the control panel form and this will help us to get our control panel on plone site.
Register the Control panel
This was just the first step, but now after defining the control panel we have to register the control panel in the configuration.zcml in the generic way.
Here is the snippet of code done to register the control panel :-
<include file="permissions.zcml" /> |
<!-- Filter Control Panel --> |
<browser:page |
name="safe_html_transform-settings" |
for="Products.CMFPlone.interfaces.IPloneSiteRoot" |
layer="..interfaces.IExperimentalSafeHtmlTransformLayer" |
class=".controlpanel.FilterControlPanel" |
permission="experimental.safe_html.controlpanel.Filtering" |
/> |
Here we have registered the browser page with the name safe_html_transfrom-settings, for IPloneSiteRoot of CMFPlone and using our own add-on browser layer and importing our controlpanel class.
Adding permissions for control panel
We will notice that we have added the permissions at the end of the setup and for that we will create a separate file named permissions.zcml and import that file in the configuartion.zcml.
The permission.zcml file looks like this :-
<configure xmlns="http://namespaces.zope.org/zope"> <permission id="experimental.safe_html.controlpanel.Filtering" title="Plone Site Setup: Filtering"> <role name="Manager"/> <role name="Site Administrator"/> </permission> </configure> | |||||||||||||||||||||
After adding these permissions to generic setup and configuring the control panel we will be able to see the controlpanel on the plone site. Here is the snippet | |||||||||||||||||||||
Finally after that the control panel thing is working perfectly. What is Next ? After that the main thing left before mid-term evaluation is to register the safe_html trasnsform in the add-on and BTW the safe_html transform is almost ready. I will explain that in next blog. Hope you like it!! Cheers!! Happy Coding. | |||||||||||||||||||||
Comments
Post a Comment