What's the best way to disable portlet types site-wide in Plone 4.1? The default setup gives ~10 portlet types, but the site users have use case only for few (static text, news).
Portlets are registered as utilities with the IPortletType
interface with the zope component machinery. These registrations are generated for you when registering portlets with portlets.xml. The portlet management UI then uses these utility registrations to enumerate portlets you can add.
Luckily, plone.portlets.utils
provides a handy API to unregister these portlets again:
def unregisterPortletType(site, addview):
"""Unregister a portlet type.
site is the local site where the registration was made. The addview
should is used to uniquely identify the portlet.
"""
The addview
parameter is a string, and is the same as used in a portlet.xml registration. For example, the calendar portlet is registered as:
<portlet
addview="portlets.Calendar"
title="Calendar portlet"
description="A portlet which can render a calendar."
i18n:attributes="title;
description"
>
<for interface="plone.app.portlets.interfaces.IColumn" />
<for interface="plone.app.portlets.interfaces.IDashboard" />
</portlet>
You can thus remove the calendar portlet from your site by running the following code snippet:
from plone.portlets.utils import unregisterPortletType
unregisterPortletType(site, 'portlets.Calendar')
You can also just use the GenericSetup portlets.xml file to remove the portlets during setup time, just list the portlets addview
parameter and add a remove
attribute to the element:
<?xml version="1.0"?>
<portlets>
<portlet addview="portlets.Calendar" remove="true" />
</portlets>
Thanks to David Glick for finding that one for us.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With