开发者

Plone Content Type-Specific Portlet Assignment

开发者 https://www.devze.com 2023-04-05 06:47 出处:网络
I\'m developing a content type for Plone 4, and I\'d like to block all user, group, and context portlets it may inherit from its parent object. I\'m thoroughly confused by the documentation at this po

I'm developing a content type for Plone 4, and I'd like to block all user, group, and context portlets it may inherit from its parent object. I'm thoroughly confused by the documentation at this point–in portlets.xml, <blacklist/> only seems to address path-specific blocking. <assignment/> seems like what I want, but it seems too specific–I don't want to manage the assignment for all possible portlets on my content type.

There are hints that I've found that customizing an ILeftColumn and IRightColumn portlet manager specific to the content type, but I can't find any good examples. Does anyone have any hints or suggestions? I feel like I'm missin开发者_如何学JAVAg something dead simple.


to prevent the portlet aquisition and maintain the possibility of adding portlert you can add an event listener on the creation of your contents that auto blocks the aquisition.

Like this:

    <subscriber
        for="my.package.interfaces.IMyContent
             zope.app.container.interfaces.IObjectAddedEvent"                 
handler=".subscribers.blockPortletsUpponMyContentCreation"
                  />

and than do this:

from zope.component import getMultiAdapter, getUtility
from plone.portlets.interfaces import IPortletManager
from plone.portlets.interfaces import ILocalPortletAssignmentManager
from plone.portlets.constants import USER_CATEGORY
from plone.portlets.constants import GROUP_CATEGORY
from plone.portlets.constants import CONTENT_TYPE_CATEGORY
from plone.portlets.constants import CONTEXT_CATEGORY

def blockPortletsUpponMyContentCreation(mycontent, event):
    for manager_name in ('plone.leftcolumn','plone.rightcolumn'):
        manager = getUtility(IPortletManager, name=manager_name)
        assignable = getMultiAdapter((mycontent, manager,), ILocalPortletAssignmentManager)
        for category in (GROUP_CATEGORY, CONTENT_TYPE_CATEGORY,CONTEXT_CATEGORY,USER_CATEGORY):
            assignable.setBlacklistStatus(category, 1)

Note: this code is inspired by the plone.app.portlet manage view

Edit 19/08/2011: included fixes as suggested by @will in my untested code...so now is tested


Do the assignment to your portaltype live on a site via Sitesetup (controlpanel) -> Types -> "Manage portlets assigned to this content type".

Then export the configuration via ZMI -> portal_setup -> Export-Tab -> select 'Portlets' -> click 'export' on bottom.

Extract the types/YourType.xml-file and copy the relevant parts in your package's profiles/default/types/YourType.xml.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号