Skip to content

Commit 579492d

Browse files
committed
Adds docs for creating custom control panel #1909 revision
1 parent e1b4aac commit 579492d

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

docs/developer-guide/create-control-panel.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,41 @@ This chapter describes how to create a control panel for your Plone add-on, whet
1515

1616
It also covers advanced topics—including how to group fields in your control panel—and provides a schema field reference, troubleshooting tips, control panel file structure, and a Plone REST API compatibility reference.
1717

18+
[`plonecli`](https://pypi.org/project/plonecli/) automates all the manual steps to create a control panel.
19+
This chapter will walk through all those steps as well.
1820

19-
## Creation approaches
2021

21-
There are two approaches to create a control panel for your Plone add-on:
22+
## `plonecli`
2223

23-
- [`plonecli`](https://pypi.org/project/plonecli/)
24-
- manual
24+
You can install `plonecli` as any other Python package.
25+
Since it's used for development, it's advantageous to install it in your user environment, thus making it available to all your Plone projects.
2526

27+
```shell
28+
pip install plonecli --user
29+
```
2630

27-
### `plonecli`
28-
29-
To add a control panel to your add-on, you can use [`plonecli`](https://pypi.org/project/plonecli/) as follows.
31+
You can automatically create a control panel using the following command.
3032

3133
```shell
3234
plonecli add controlpanel
3335
```
3436

3537
This creates the control panel Python file in the control panel's folder where you can define your control panel schema fields.
38+
It also goes through all the following steps to create a control panel.
3639

3740

38-
### Manual
41+
## Steps to create a control panel
3942

40-
To manually create a control panel, go through the following steps.
43+
Whether performed automatically with `plonecli` or manually, the following steps are required to create a control panel.
4144

4245
- Define the settings interface and form.
4346
- Register the control panel view in ZCML.
4447
- Add the control panel to the Plone control panel listing.
4548
- Set default values in the registry.
49+
- Register the control panel in XML.
4650

47-
#### Define the settings interface and form
51+
52+
### Define the settings interface and form
4853

4954
Create a Python module, {file}`mypackage/controlpanel/settings.py`, that defines your control panel's settings interface and form class as follows.
5055

@@ -86,7 +91,7 @@ MyControlPanelView = layout.wrap_form(MyControlPanelForm, ControlPanelFormWrappe
8691
```
8792

8893

89-
#### Register the control panel view
94+
### Register the control panel view
9095

9196
Create a file {file}`mypackage/controlpanel/configure.zcml` with the following content to register the control panel view in ZCML.
9297

@@ -107,7 +112,7 @@ Create a file {file}`mypackage/controlpanel/configure.zcml` with the following c
107112
</configure>
108113
```
109114

110-
Make sure to include the above file in your package's main {file}`mypackage/configure.zcml` as shown by the highlighted line below.
115+
Include the above file in your package's main {file}`mypackage/configure.zcml`, as shown by the highlighted line below.
111116

112117
{emphasize-lines="9"}
113118
```xml
@@ -124,7 +129,8 @@ Make sure to include the above file in your package's main {file}`mypackage/conf
124129
</configure>
125130
```
126131

127-
#### Add the control panel entry
132+
133+
### Add the control panel entry
128134

129135
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.
130136

@@ -165,7 +171,7 @@ These values correspond to the groups in {guilabel}`Site Setup`.
165171
: {guilabel}`Advanced`
166172

167173

168-
#### Set default values in the registry
174+
### Set default values in the registry
169175

170176
Define default values for your settings in {file}`mypackage/profiles/default/registry.xml`.
171177

@@ -182,9 +188,9 @@ Define default values for your settings in {file}`mypackage/profiles/default/reg
182188
```
183189

184190

185-
#### Register a control panel
191+
### Register the control panel
186192

187-
To manually register a view as a control panel, add the following registration to your {file}`/profiles/default/controlpanel.xml`.
193+
To register the view as a control panel, add the following registration to your {file}`/profiles/default/controlpanel.xml`.
188194

189195
```xml
190196
<?xml version="1.0"?>
@@ -207,7 +213,12 @@ To manually register a view as a control panel, add the following registration t
207213
</object>
208214
```
209215

210-
After you perform the above steps for the manual process, you must restart the Plone site. To stop a running Plone instance, press {kbd}`ctrl-c` in the terminal where Plone is running. To start it again, use the appropriate command based on your installation method:
216+
217+
## Load your control panel
218+
219+
After performing the above steps, you must restart the Plone site.
220+
To stop a running Plone instance, press {kbd}`ctrl-c` in the terminal where Plone is running.
221+
To start it again, use the appropriate command based on your installation method.
211222

212223
`````{tab-set}
213224
@@ -249,6 +260,7 @@ make frontend-start
249260

250261
Your control panel should now appear in {guilabel}`Site Setup`.
251262

263+
252264
## Access your settings in code
253265

254266
You can access your settings in Python code as follows.
@@ -265,6 +277,7 @@ my_setting_value = settings.my_setting
265277
my_choice_value = settings.my_choice
266278
```
267279

280+
268281
## Use `FieldSet` to group fields
269282

270283
For complex control panels, you can group fields together as in the following example.
@@ -368,6 +381,7 @@ mypackage/
368381
└── registry.xml
369382
```
370383

384+
371385
## REST API compatibility
372386

373387
For better integration between Plone's backend and its frontend Volto, you can create REST API compatible control panels using the adapter pattern.

0 commit comments

Comments
 (0)