9
9
10
10
(backend-controlpanels-label)=
11
11
12
- # Control panels
12
+ # Create a control panel
13
13
14
- ## Adding a control panel
14
+ There are two approaches to create a control panel for your Plone add-on:
15
15
16
- There are two approaches to creating a control panel for your Plone add-on:
16
+ - [ ` plonecli ` ] ( https://pypi.org/project/plonecli/ )
17
+ - manual
17
18
18
- ### Approach 1: Using plonecli
19
19
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.
21
23
22
24
``` shell
23
25
plonecli add controlpanel
24
26
```
25
27
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
+
27
30
28
- ### Approach 2: Creating a Custom Control Panel Manually
31
+ ## Manual
29
32
30
- Creating a custom control panel involves these main steps:
33
+ To manually create a control panel, go through the following steps.
31
34
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.
37
39
38
- #### 1. Define the Settings Interface and Form
39
40
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.
41
44
42
45
``` python
43
46
# mypackage/controlpanel/settings.py
@@ -76,9 +79,10 @@ class MyControlPanelForm(RegistryEditForm):
76
79
MyControlPanelView = layout.wrap_form(MyControlPanelForm, ControlPanelFormWrapper)
77
80
```
78
81
79
- #### 2. Register the Control Panel View in ZCML
80
82
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.
82
86
83
87
``` xml
84
88
<!-- mypackage/controlpanel/configure.zcml -->
@@ -97,8 +101,9 @@ Next, register the control panel view in ZCML:
97
101
</configure >
98
102
```
99
103
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.
101
105
106
+ {emphasize-lines="9"}
102
107
``` xml
103
108
<!-- mypackage/configure.zcml -->
104
109
<configure
@@ -113,9 +118,9 @@ Make sure to include this configure.zcml from your package's main configure.zcml
113
118
</configure >
114
119
```
115
120
116
- #### 3. Add the Control Panel Entry
121
+ ### Add the control panel entry
117
122
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.
119
124
120
125
``` xml
121
126
<!-- mypackage/profiles/default/controlpanel.xml -->
@@ -135,16 +140,28 @@ Create a controlpanel.xml in your package's GenericSetup profile to add your con
135
140
</object >
136
141
```
137
142
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
144
154
145
- #### 4. Set Default Values in the Registry
155
+ ` plone-security `
156
+ : Security settings
146
157
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 ` .
148
165
149
166
``` xml
150
167
<!-- mypackage/profiles/default/registry.xml -->
@@ -158,9 +175,10 @@ Define default values for your settings in registry.xml:
158
175
</registry >
159
176
```
160
177
161
- #### 5. Accessing Your Settings in Code
162
178
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.
164
182
165
183
``` python
166
184
from plone.registry.interfaces import IRegistry
@@ -174,12 +192,13 @@ my_setting_value = settings.my_setting
174
192
my_choice_value = settings.my_choice
175
193
```
176
194
177
- ## Registering a Control panel
178
195
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 ` .
180
199
181
200
``` xml
182
- <?xml version =" 1.0" ?>
201
+ <?xml version =" 1.0" ?>
183
202
<object
184
203
name =" portal_control-panel"
185
204
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
199
218
</object >
200
219
```
201
220
202
- ## Advanced Topics
203
221
204
- ### Using FieldSet for Grouping Fields
222
+ ## Use ` FieldSet ` to group fields
205
223
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.
207
225
208
226
``` python
209
227
from plone.supermodel import model
@@ -235,39 +253,59 @@ class IMyControlPanelSettings(Interface):
235
253
)
236
254
```
237
255
238
- ### Common Schema Fields
239
256
240
- Here are some commonly used schema field types:
257
+ ## Common schema fields
241
258
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.
250
260
251
- ### Note on Updating Control Panel Fields
261
+ ` schema.TextLine `
262
+ : For single-line text
252
263
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.
254
294
255
- 1 . Run the appropriate upgrade steps, or
256
- 2 . Reinstall your add-on, or
257
- 3 . Test with a fresh site installation
258
295
259
296
## Troubleshooting
260
297
261
298
If your control panel doesn't appear or doesn't work as expected:
262
299
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
+
267
305
268
- ## Complete Example
306
+ ## Example file structure
269
307
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.
271
309
272
310
```
273
311
mypackage/
@@ -286,4 +324,4 @@ mypackage/
286
324
287
325
``` {seealso}
288
326
See the chapter {ref}`training:controlpanel-label` from the Mastering Plone 6 Training.
289
- ```
327
+ ```
0 commit comments