Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override a Plone event subscriber

I need to extend a Plone product (Products.Poi) with a second product. In the extension product i need to override a subscriber event of the original. I tried to subscribe in an override.zcml an event with the same name but the second event don't override the first but all two are execute.

Here http://plone.org/products/dexterity/documentation/manual/five.grok/core-components/events seem that is not possible:

Unlike adapters, you cannot override an event subscriber by using a more specific interface. Each and every applicable event subscriber will be executed when an event is fired.

Someone has a trick?

Thanks Alex

like image 868
Almalerik Avatar asked Jan 27 '13 05:01

Almalerik


2 Answers

Simone Orsi gave me a solution: z3c.unconfigure.

This product permit to disable zcml configuration.

To use it, I executed this step on my extented Poi product:

  1. Added "z3c.unconfigure" as install_requires in the setup.py
  2. Create event.py with the new definition of update_tracker_watchers
  3. In the overrides.zcml add this line to unconfigure Products.Poi.events.update_tracker_watchers and to register my new event

<include package="z3c.unconfigure" file="meta.zcml" />
<unconfigure>
    <subscriber
        for="Products.Poi.interfaces.ITracker
                  Products.Archetypes.interfaces.IObjectEditedEvent"
        handler="Products.Poi.events.update_tracker_watchers"
    />
</unconfigure>
<subscriber
    for="Products.Poi.interfaces.ITracker
              Products.Archetypes.interfaces.IObjectEditedEvent"
    handler=".events.update_tracker_watchers"
/>

like image 151
Almalerik Avatar answered Nov 15 '22 11:11

Almalerik


When you specified the overrides.zcml, you also need to register the zcml override in buildout? Take a look at: http://developer.plone.org/components/zcml.html?highlight=zcml#overrides It'd be something like: zcml = my.package-overrides

Additionally, you can try using the z3c.unconfigure package: http://pypi.python.org/pypi/z3c.unconfigure

like image 35
vangheem Avatar answered Nov 15 '22 11:11

vangheem