Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a control panel in Plone #4131

Open
sneridagh opened this issue Mar 2, 2025 · 2 comments
Open

How to create a control panel in Plone #4131

sneridagh opened this issue Mar 2, 2025 · 2 comments

Comments

@sneridagh
Copy link
Member

Yesterday I found myself trying to create a control panel in Plone and I discovered that there is nothing to be found in https://6.docs.plone.org

I also found this issue: plone/documentation#1304 in the docs repo so it's known since two years ago at least.

I'm opening this issue in here too, in order to raise awareness.

@rohnsha0
Copy link
Contributor

rohnsha0 commented Mar 7, 2025

AFAIK, there are contents about the same for a backend addon. However, nothing for doing it here. However, same can be done using Products.CMFPlone repo sitewide.

1. First, create your control panel settings interface and form

# testcp.py
from zope import schema
from zope.interface import Interface
from plone.app.registry.browser.controlpanel import RegistryEditForm, ControlPanelFormWrapper
from plone.z3cform import layout

class IMyControlPanelSettings(Interface):
    my_setting = schema.TextLine(
        title=u'My Setting',
        description=u'Enter the value for my setting',
        required=False,
        default=u''
    )
    my_choice = schema.Choice(
        title=u'My Choice',
        description=u'Select a value for my choice',
        required=False,
        default=u'value3',
        values=['value1', 'value2', 'value3']
    )

class MyControlPanelForm(RegistryEditForm):
    schema = IMyControlPanelSettings
    schema_prefix = "my.addon"
    label = u"My Addon Settings"

MyControlPanelView = layout.wrap_form(MyControlPanelForm, ControlPanelFormWrapper)

2. Register the control panel view in ZCML

<!-- controlpanel/browser/configure.zcml -->
<browser:page
    name="my-controlpanel"
    for="Products.CMFPlone.interfaces.IPloneSiteRoot"
    class=".testcp.MyControlPanelView"
    permission="cmf.ManagePortal" />

3. Add the control panel entry

<!-- profiles/default/controlpanel.xml -->
<configlet
    title="My Addon Settings"
    action_id="my-controlpanel"
    appId="my.addon"
    category="plone-general"
    condition_expr=""
    icon_expr="string:puzzle"
    url_expr="string:${portal_url}/@@my-controlpanel"
    visible="True">
    <permission>Manage portal</permission>
</configlet>

4. Set default values in the registry

<!-- profiles/default/registry.xml -->
<records interface="Products.CMFPlone.controlpanel.browser.testcp.IMyControlPanelSettings" prefix="my.addon">
    <value key="my_setting">default value</value>
    <value key="my_choice">value3</value>
</records>

Image

Hope this helps! let me knw if it fails @sneridagh.
note: if fields are changed then it doesnt reflect immediately and needs a new site to get the reflection. @davisagli is there any workaround?

@mauritsvanrees
Copy link
Member

There is documentation in plone.app.registry. At a very brief glance, this looks about the same as above.
But yes, having it in the docs would be good. Even a link could already help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants