如何更改 portlet 顺序(先放置父 portlet)

How to change portlet order (put parent portlets first)

我如何重新排序 portlet,以便继承的父 portlet 排在当前项目的 portlet 之前?

我知道有两种解决方案

collective.weightedportlets

您可以为每个 portlet 定义一个权重,无论 section/group 该 portlet 是哪个(用户、上下文、类型、继承的)。 版本 1.1 与 Plone 4.3 兼容。

Solgema.PortletsManager

基本上做类似collective.weightedportlets的事情,但它可以由D'n'D完成,它扩展了manage-portlets的UI。

您可以侵入 portlet 检索器,但我不建议这样做。

PS: 如果你想写你自己的 portlet 检索器,也检查 collective.weightedportlets :-)

More about how plone renders portlets.

Mathias 的解决方案似乎更简单;无论如何,如果您不想安装第三方产品,我想保留此文档。

您只需编写适配器即可更改 portlet 的排序方式。例如,下面的例子对提供 IATImage 接口(图像)的任何对象上的 portlet 进行了重新排序,因此首先呈现内容类型 portelt,然后是组,最后是上下文:

from plone.portlets.interfaces import IPortletManager
from plone.portlets.interfaces import IPortletRetriever
from plone.portlets.retriever import PortletRetriever as BaseRetriever
from Products.ATContentTypes.interfaces import IATImage
from zope.component import adapts
from zope.interface import implements


class PortletRetriever(BaseRetriever):
    implements(IPortletRetriever)
    adapts(IATImage, IPortletManager)

    def getPortlets(self):
        assignments = super(PortletRetriever, self).getPortlets()
        context = [p for p in assignments if p['category'] == 'context']
        group = [p for p in assignments if p['category'] == 'group']
        content_type = [p for p in assignments if p['category'] == 'content_type']
        new_assignments = content_type + group + context
        return new_assignments

不要忘记在您的 ZCML 文件中使用以下内容注册您的适配器:

<configure xmlns="http://namespaces.zope.org/zope">
  ...
  <adapter factory=".adapters.PortletRetriever" />
  ...
</configure>