99
1010(backend-controlpanels-label)=
1111
12- # Control panels
12+ # Create a control panel
1313
14- ## Adding a control panel
14+ There are two approaches to create a control panel for your Plone add-on:
1515
16- There are two approaches to creating a control panel for your Plone add-on:
16+ - [ ` plonecli ` ] ( https://pypi.org/project/plonecli/ )
17+ - manual
1718
18- ### Approach 1: Using plonecli
1919
20- To add a control panel to your add-on, you can use [ ` plonecli ` ] ( https://pypi.org/project/plonecli/ ) as follows:
20+ ## ` plonecli `
21+
22+ To add a control panel to your add-on, you can use [ ` plonecli ` ] ( https://pypi.org/project/plonecli/ ) as follows.
2123
2224``` shell
2325plonecli add controlpanel
2426```
2527
26- This will create the control panel Python file in the control panel's folder where you can define your control panel schema fields.
28+ This creates the control panel Python file in the control panel's folder where you can define your control panel schema fields.
29+
2730
28- ### Approach 2: Creating a Custom Control Panel Manually
31+ ## Manual
2932
30- Creating a custom control panel involves these main steps:
33+ To manually create a control panel, go through the following steps.
3134
32- 1 . Define an interface for your settings
33- 2 . Create a form based on that interface
34- 3 . Register the control panel view in ZCML
35- 4 . Add the control panel to the Plone control panel listing
36- 5 . Set default values in the registry
35+ - Define the settings interface and form.
36+ - Register the control panel view in ZCML.
37+ - Add the control panel to the Plone control panel listing.
38+ - Set default values in the registry.
3739
38- #### 1. Define the Settings Interface and Form
3940
40- First, create a Python module that defines your control panel's settings interface and form class:
41+ ### Define the settings interface and form
42+
43+ Create a Python module, {file}` mypackage/controlpanel/settings.py ` , that defines your control panel's settings interface and form class as follows.
4144
4245``` python
4346# mypackage/controlpanel/settings.py
@@ -76,9 +79,10 @@ class MyControlPanelForm(RegistryEditForm):
7679MyControlPanelView = layout.wrap_form(MyControlPanelForm, ControlPanelFormWrapper)
7780```
7881
79- #### 2. Register the Control Panel View in ZCML
8082
81- Next, register the control panel view in ZCML:
83+ ### Register the control panel view
84+
85+ Create a file {file}` mypackage/controlpanel/configure.zcml ` with the following content to register the control panel view in ZCML.
8286
8387``` xml
8488<!-- mypackage/controlpanel/configure.zcml -->
@@ -97,8 +101,9 @@ Next, register the control panel view in ZCML:
97101</configure >
98102```
99103
100- Make sure to include this configure.zcml from your package's main configure.zcml:
104+ Make sure to include the above file in your package's main {file} ` mypackage/ configure.zcml` as shown by the highlighted line below.
101105
106+ {emphasize-lines="9"}
102107``` xml
103108<!-- mypackage/configure.zcml -->
104109<configure
@@ -113,9 +118,9 @@ Make sure to include this configure.zcml from your package's main configure.zcml
113118</configure >
114119```
115120
116- #### 3. Add the Control Panel Entry
121+ ### Add the control panel entry
117122
118- Create a controlpanel.xml in your package's GenericSetup profile to add your control panel to the Plone control panel listing:
123+ Create a {file} ` mypackage/profiles/default/ controlpanel.xml` in your package's GenericSetup profile with the following content to add your control panel to the Plone control panel listing.
119124
120125``` xml
121126<!-- mypackage/profiles/default/controlpanel.xml -->
@@ -135,16 +140,28 @@ Create a controlpanel.xml in your package's GenericSetup profile to add your con
135140</object >
136141```
137142
138- The category attribute can be one of:
139- - ` plone-general ` - General settings
140- - ` plone-content ` - Content-related settings
141- - ` plone-users ` - Users and groups settings
142- - ` plone-security ` - Security settings
143- - ` plone-advanced ` - Advanced settings
143+ The category attribute can be one of the following values.
144+ These values correspond to the groups in Site Setup.
145+
146+ ` plone-general `
147+ : General settings
148+
149+ ` plone-content `
150+ : Content-related settings
151+
152+ ` plone-users `
153+ : Users and groups settings
144154
145- #### 4. Set Default Values in the Registry
155+ ` plone-security `
156+ : Security settings
146157
147- Define default values for your settings in registry.xml:
158+ ` plone-advanced `
159+ : Advanced settings
160+
161+
162+ ### Set default values in the registry
163+
164+ Define default values for your settings in {file}` mypackage/profiles/default/registry.xml ` .
148165
149166``` xml
150167<!-- mypackage/profiles/default/registry.xml -->
@@ -158,9 +175,10 @@ Define default values for your settings in registry.xml:
158175</registry >
159176```
160177
161- #### 5. Accessing Your Settings in Code
162178
163- You can access your settings in Python code as follows:
179+ ### Access your settings in code
180+
181+ You can access your settings in Python code as follows.
164182
165183``` python
166184from plone.registry.interfaces import IRegistry
@@ -174,12 +192,13 @@ my_setting_value = settings.my_setting
174192my_choice_value = settings.my_choice
175193```
176194
177- ## Registering a Control panel
178195
179- To manually register a view as a control panel, add the following registration to your ` /profiles/default/controlpanel.xml ` .
196+ ## Register a control panel
197+
198+ To manually register a view as a control panel, add the following registration to your {file}` /profiles/default/controlpanel.xml ` .
180199
181200``` xml
182- <?xml version =" 1.0" ?>
201+ <?xml version =" 1.0" ?>
183202 <object
184203 name =" portal_control-panel"
185204 xmlns : i18n =" http://xml.zope.org/namespaces/i18n"
@@ -199,11 +218,10 @@ To manually register a view as a control panel, add the following registration t
199218 </object >
200219```
201220
202- ## Advanced Topics
203221
204- ### Using FieldSet for Grouping Fields
222+ ## Use ` FieldSet ` to group fields
205223
206- For complex control panels, you might want to group fields together:
224+ For complex control panels, you can group fields together as in the following example.
207225
208226``` python
209227from plone.supermodel import model
@@ -235,39 +253,59 @@ class IMyControlPanelSettings(Interface):
235253 )
236254```
237255
238- ### Common Schema Fields
239256
240- Here are some commonly used schema field types:
257+ ## Common schema fields
241258
242- - ` schema.TextLine ` : For single-line text
243- - ` schema.Text ` : For multi-line text
244- - ` schema.Bool ` : For boolean values
245- - ` schema.Int ` : For integer values
246- - ` schema.Float ` : For floating-point values
247- - ` schema.Choice ` : For selection from a list of values
248- - ` schema.Datetime ` : For date and time values
249- - ` schema.List ` : For list of values
259+ The following is a list of commonly used schema field types.
250260
251- ### Note on Updating Control Panel Fields
261+ ` schema.TextLine `
262+ : For single-line text
252263
253- When you modify the fields in your control panel settings interface, the changes won't be automatically reflected in existing sites. You'll need to:
264+ ` schema.Text `
265+ : For multi-line text
266+
267+ ` schema.Bool `
268+ : For boolean values
269+
270+ ` schema.Int `
271+ : For integer values
272+
273+ ` schema.Float `
274+ : For floating-point values
275+
276+ ` schema.Choice `
277+ : For selection from a list of values
278+
279+ ` schema.Datetime `
280+ : For date and time values
281+
282+ ` schema.List `
283+ : For list of values
284+
285+
286+ ## Modify control panel fields
287+
288+ When you modify the fields in your control panel settings interface, the changes won't be automatically reflected in existing sites.
289+ You'll need to perform one or more of the following steps.
290+
291+ - Run the appropriate upgrade steps.
292+ - Reinstall your add-on.
293+ - Test with a fresh site installation.
254294
255- 1 . Run the appropriate upgrade steps, or
256- 2 . Reinstall your add-on, or
257- 3 . Test with a fresh site installation
258295
259296## Troubleshooting
260297
261298If your control panel doesn't appear or doesn't work as expected:
262299
263- 1 . Verify that all ZCML is properly registered
264- 2 . Check for errors in the Plone error log
265- 3 . Ensure your GenericSetup profiles are correctly installed
266- 4 . Validate that the interface path in registry.xml matches your actual Python path
300+ - Verify that all ZCML is properly registered
301+ - Check for errors in the Plone error log
302+ - Ensure your GenericSetup profiles are correctly installed
303+ - Validate that the interface path in registry.xml matches your actual Python path
304+
267305
268- ## Complete Example
306+ ## Example file structure
269307
270- Below is a complete file structure for a simple add-on with a control panel:
308+ Below is a complete example file structure for a basic add-on with a control panel.
271309
272310```
273311mypackage/
@@ -286,4 +324,4 @@ mypackage/
286324
287325``` {seealso}
288326See the chapter {ref}`training:controlpanel-label` from the Mastering Plone 6 Training.
289- ```
327+ ```
0 commit comments