You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This chapter describes how to add custom event handlers for your type.
13
13
14
14
Zope (and so Plone) has a powerful event notification and subscriber subsystem.
15
15
Events notifications are already fired at several places.
16
16
17
-
With custom subscribers to these events more dynamic functionality can be added.
17
+
With custom subscribers to these events, more dynamic functionality can be added.
18
18
It is possible to react when something happens to objects of a specific type.
19
19
20
-
Zope’s event model is *synchronous*.
21
-
When an event is broadcast (via the `notify()` function from the [zope.event] package) all registered event handlers will be called.
22
-
This happens for example from the `save` action of an add form, on move or delete of content-objects.
23
-
There is no guarantee of which order the event handlers will be called in, however.
20
+
Zope's event model is *synchronous*.
21
+
When an event is broadcast (via the `notify()` function from the [`zope.event`](https://pypi.org/project/zope.event/) package), all registered event handlers will be called.
22
+
This happens, for example, from the `save` action of an add form, or on move or delete of contentobjects.
23
+
There is no guarantee in which order the event handlers will be called.
24
24
25
25
Each event is described by an interface, and will typically carry some information about the event.
26
26
Some events are known as *object events*, and provide `zope.component.interfaces.IObjectEvent`.
27
-
These have an `object` attribute giving access to the (content) object that the event relates to.
27
+
These have an `object` attribute giving access to the content object that the event relates to.
28
28
Object events allow event handlers to be registered for a specific type of object as well as a specific type of event.
29
29
30
30
Some of the most commonly used event types in Plone are shown below.
: fired by the standard add form just after an object has been created, but before it has been added on the container.
36
-
Note that it is often easier to write a handler for `IObjectAddedEvent` (see below), because at this point the object has a proper acquisition context.
34
+
: Fired by the standard add form just after an object has been created, but before it has been added on the container.
35
+
Note that it is often easier to write a handler for `IObjectAddedEvent` (see below), because at this point the object has a proper acquisition context.
-First argument to `for` is an interface describing the object type.
118
-
-Second argument is the event type.
119
-
- The arguments to the function reflects these two, so the first argument is the `IPresenter` instance and the second is an `IObjectAddedEvent` instance.
110
+
- The first argument to `for` is an interface describing the object type.
111
+
- The second argument is the event type.
112
+
-The arguments to the function reflects these two, so the first argument is the `IPresenter` instance, and the second is an `IObjectAddedEvent` instance.
120
113
121
114
```xml
122
115
<subscriber
@@ -127,5 +120,3 @@ And register it in ZCML:
127
120
```
128
121
129
122
There are many ways to improve this rather simplistic event handler, but it illustrates how events can be used.
0 commit comments