Skip to content

Commit 56935e0

Browse files
authored
docs: Clarify how to re-use image and links in custom plugins (#176)
1 parent 346a445 commit 56935e0

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

docs/source/how-to/add-frontend-plugins.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,58 @@ functionality of your plugin. These mixins are:
126126
* **Title**: Adds an optional title to the plugin which can be used to display
127127
a title above the plugin or just to simplify the navigation of the plugin tree.
128128

129+
Each mixin comes in two flavours, one for the plugin and one for the plugin form.
130+
The plugin mixin is used to add the functionality to the plugin, while the form
131+
mixin is used to add their fields to the plugin form. The mixins are
132+
designed to be used together.
129133

134+
For example, if you want to use the attributes mixin, you need to add the
135+
``AttributesMixin`` to your plugin and the ``AttributesMixinForm`` to your
136+
plugin form::
130137

138+
from djangocms_frontend.cms_plugins import AttributesMixin, AttributesMixinForm
131139

140+
class YourPlugin(AttributesMixin, CMSUIPlugin):
141+
...
142+
143+
class YourPluginForm(AttributesMixinForm, EntangledModelForm):
144+
...
145+
146+
Re-using links and images
147+
-------------------------
148+
149+
django CMS Frontend comes with a set of classes that can be used to re-use links
150+
and images in your plugin. These mixins are:
151+
152+
* **LinkPluginMixin**: Adds a link to the plugin. The link can be used to link
153+
the plugin to a page, a file or an external URL. Include **GetLinkMixin** with
154+
your plugin model and base the admin form on **AbstractLinkForm** (can also
155+
be used as a mixin)::
156+
157+
from djangocms_frontend.contrib.link.cms_plugins import LinkPluginMixin
158+
from djangocms_frontend.contrib.link.models import GetLinkMixin
159+
from djangocms_frontend.contrib.link.forms import AbstractLinkForm
160+
161+
class YourPlugin(LinkPluginMixin, CMSUIPlugin):
162+
...
163+
164+
class YourPluginForm(AbstractLinkForm):
165+
link_is_optional = False # True, if the link is optional
166+
...
167+
168+
class YourPluginModel(GetLinkMixin, FrontendUIItem):
169+
...
170+
171+
172+
* **ImageMixin**: Adds an image to the plugin *model*. Base your plugin form on
173+
**ImageForm** (can also be used as a mixin)::
174+
175+
from djangocms_frontend.contrib.image.models import ImageMixin
176+
from djangocms_frontend.contrib.image.forms import ImageForm
177+
178+
class YourPluginForm(ImageForm):
179+
...
180+
181+
class YourPluginModel(ImageMixin, FrontendUIItem):
182+
image_field = "image" # The name of the image field in the config JSON
183+
...

0 commit comments

Comments
 (0)