Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plone Content Type-Specific Portlet Assignment

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 missing something dead simple.

like image 654
Will Avatar asked Sep 15 '11 14:09

Will


Video Answer


1 Answers

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

like image 74
Giacomo Spettoli Avatar answered Sep 28 '22 06:09

Giacomo Spettoli