Blog Entry 13 years, 2 months ago

Create new (control panel) setting page in Plone 4

This is the simple guide for creating a terribly simple config of control panel of Plone 4, most of the note is taken from here (http://plone.org/documentation/kb/how-to-create-a-plone-control-panel-with-plone.app.registry). Assume we already have a Plone 4 package, called pure.theme.

This is the simple guide for creating a terribly simple config of control panel of Plone 4, most of the note is taken from here (http://plone.org/documentation/kb/how-to-create-a-plone-control-panel-with-plone.app.registry)

Assume we already have a Plone 4 package, called pure.theme

1. Create new module inside pure.theme/browser/ (let's name it: firstcpl.py) which contains configlet view, interface...:

File: browser/firstcpl.py

Define the form schema inside view interface:

class IFirstControlPanelView(Interface):
    your_name = schema.TextLine(title=_(u"Your name"),
                                description=_(u"This should be your real name"),
                                required=False,
                                default=u'',)

Define the Form class, which is subclass of RegistryEditForm:

class FirstControlPanelForm(controlpanel.RegistryEditForm):
    schema = IFirstControlPanelView
    label = _(u'Your misc settings')
    description = _(u'Description here')

    def updateFields(self):
        super(FirstControlPanelForm, self).updateFields()

    def updateWidgets(self):
        super(FirstControlPanelForm, self).updateWidgets()  

And the wrapper for control panel view:

class FirstControlPanelView(controlpanel.ControlPanelFormWrapper):
    form = FirstControlPanelForm

2. Add new entry inside the configure.zcml for the new config view:

File: browser/configure.zcml

  <include package="plone.app.registry" />

  <browser:page
      name = 'pure-settings'
      for = 'plone.app.layout.navigation.interfaces.INavigationRoot'
      class = '.firstcplview.FirstControlPanelView'
      permission = 'cmf.ManagePortal'
      />

3. Update the control panel profile (profiles/default/controlpanel.xml) to register the new configlet:

File: profiles/default/controlpanel.xml

<?xml version="1.0"?>
<object name="portal_controlpanel" meta_type="Plone Control Panel Tool">
 <configlet title="Pure Settings" action_id="pure" appId="pure.theme"
    category="Products" condition_expr=""
    icon_expr="string:$portal_url/logoIcon.png"
    url_expr="string:${portal_url}/@@pure-settings" visible="True">
  <permission>Manage portal</permission>
 </configlet>
</object>

4. Update the registry profile (profiles/default/registry.xml) to add the new registry record(s):

File: profiles/default/registry.xml

Here we have only one record

<registry>
  <records interface="pure.theme.browser.firstcplview.IFirstControlPanelView" />
</registry>

After all is done, let's restart the instance and install/reinstall the package to see the new stuffs.

Recent Reads