Skip to content

Adds docs for creating custom control panel #1909 revision #1939

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

Open
wants to merge 10 commits into
base: rohnsha0-control-panel
Choose a base branch
from
48 changes: 31 additions & 17 deletions docs/developer-guide/create-control-panel.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,41 @@ This chapter describes how to create a control panel for your Plone add-on, whet

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.

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

## Creation approaches

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

- [`plonecli`](https://pypi.org/project/plonecli/)
- manual
You can install `plonecli` as any other Python package.
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.

```shell
pip install plonecli --user
```

### `plonecli`

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

```shell
plonecli add controlpanel
```

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


### Manual
## Steps to create a control panel

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

- Define the settings interface and form.
- Register the control panel view in ZCML.
- Add the control panel to the Plone control panel listing.
- Set default values in the registry.
- Register the control panel in XML.

#### Define the settings interface and form

### Define the settings interface and form

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

Expand Down Expand Up @@ -86,7 +91,7 @@ MyControlPanelView = layout.wrap_form(MyControlPanelForm, ControlPanelFormWrappe
```


#### Register the control panel view
### Register the control panel view

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

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

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

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

#### Add the control panel entry

### Add the control panel entry

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.

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


#### Set default values in the registry
### Set default values in the registry

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

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


#### Register a control panel
### Register the control panel

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

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

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:

## Load your control panel

After performing the above steps, 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.

`````{tab-set}

Expand Down Expand Up @@ -249,6 +260,7 @@ make frontend-start

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


## Access your settings in code

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


## Use `FieldSet` to group fields

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


## REST API compatibility

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