Direkt zum Inhalt | Direkt zur Navigation

Benutzerspezifische Werkzeuge
Anmelden

How to add new content on top of a folder

By default Plone adds new content to the bottom of a folder. With zope3 event-handlers you can change that behaviour easily.

Here we use event handlers to push newly-created NewsItems to the top of the page. Usefull for blog-style folders. It doesn't apply when editing existing content.

Add a new subscriber to your configure.zcml (you might want to use your site-policy- or theme-product):

<subscriber 
   for="Products.ATContentTypes.interface.news.IATNewsItem
   zope.app.container.interfaces.IObjectAddedEvent"
   handler=".newsitemmover.moveToTop" />

Create the new file newsitemmover.py containing

def moveToTop(obj, event):
   """
   Moves Items to the top of its folder
   """
   folder = obj.getParentNode()
   if folder != None:
       folder.moveObjectsToTop(obj.id)

Restart Zope.

The tricky part is to choose the correct Interfaces for the subscriber. Keep in mind that IObjectAddedEvent is called several times during adding a NewsItem. It doen't matter in this case since the item can't be any more on top than on top :-)

abgelegt unter:
pmaljhp
pmaljhp sagt
20.01.2012 11:10
Olegko
Olegko sagt
29.01.2012 15:20
74065
74065 sagt
01.02.2012 04:21
<url>http://dennisssblegh.com|dennis</url>

hey
Lovely site
4030
4030 sagt
01.02.2012 04:51
<url>http://dennisssblegh.com|dennis</url>

gday
Lovely site
hambweewope
hambweewope sagt
05.02.2012 06:16
VPN Critiquees <a href=http://vpnserviceratings.com/>vpn reviews</a>
    
 XIJNICBNP DirmEjmsoznyu
Kommentieren

Sie können einen Kommentar abgeben, indem Sie das untenstehende Formular ausfüllen. Nur Text. Web- und E-Mailadressen werden in anklickbare Links umgewandelt.