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
Copy file name to clipboardExpand all lines: docs/backend/behaviors.md
+43-37Lines changed: 43 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -119,42 +119,6 @@ This looks like so:
119
119
120
120
After you apply the profile (or uninstall and install the custom add-on), the behavior is available on the Event content type.
121
121
122
-
## How behaviors work
123
-
124
-
In Plone, behaviors can be globally enabled on content types at runtime.
125
-
With add-ons, behaviors can even be enabled even on a single content object or for a whole subtree in the content hierarchy.
126
-
127
-
### Interfaces and adapters
128
-
129
-
When a behavior is enabled for a particular object, it will be possible to adapt that object to the behavior's interface.
130
-
Otherwise, when the behavior is disabled, adaptation will fail or falls back to a more generic adapter, if any is registered.
131
-
132
-
A behavior is at least a combination of an interface (also as a form field provider), metadata such as a name, title, and description, and sometimes an adapter factory with a marker interface.
133
-
When a behavior is enabled, an interface is added to the content object to indicate its presence - it now provides the interface.
134
-
135
-
Behaviors without an adapter factory can be used either as a simple marker or to provide additional form fields.
136
-
In this case, adapting a content object with this interface returns the content object itself, because adapting an object that already provides the exact same interface returns the very same object.
137
-
Based on the now-provided interface, i.e specific views can be registered with the content type, or event handlers can be registered to respond to specific actions.
138
-
139
-
In other cases, there is also an adapter factory (usually a class), which will be invoked (initialized) to get an appropriate adapter when requested.
140
-
If an adapter factory is used an explicit marker interface is required.
141
-
142
-
With an adapter factory in place, custom getters and setters for form fields can be implemented, or even new methods i.e. for calculations or to combine data can be added.
143
-
144
-
### Registration
145
-
146
-
Behaviors are registered globally using the <plone.behavior /> {term}`ZCML` directive.
147
-
Internally, this directive registers a named utility that provides `plone.behavior.interfaces.IBehavior`, which contains combined information about the behavior such as its name, interface, factory/marker interface, and metadata.
148
-
149
-
```{seealso}
150
-
The [README file of `plone.behavior`](https://github.com/plone/plone.behavior/blob/master/README.rst) explains the concepts and different ways to register a behavior in detail.
151
-
```
152
-
153
-
### Lookup and provide
154
-
155
-
Plone content objects have logic to look up the behaviors names registered from their types configuration, the Factory Type Information (FTI).
156
-
At runtime, the logic provides the interface (or marker) from the behavior to the object.
157
-
This dynamically provided interface enables the component architecture to react to this new interface by adding additional form fields, bindings events, enabling more specific views, and more.
158
122
159
123
## Custom behaviors
160
124
@@ -314,8 +278,50 @@ plonecli add behavior
314
278
315
279
This will create the behavior Python file in the `behaviors` folder, where you can define your behaviors schema fields, and registers the behavior in the `configure.zcml`.
316
280
317
-
### Further reading on behaviors
281
+
### Further reading on working with behaviors
318
282
319
283
```{seealso}
320
284
See the chapter {ref}`training:behaviors1-label` from the Mastering Plone 6 Training.
321
285
```
286
+
287
+
## How behaviors work
288
+
289
+
```{note}
290
+
Skip this section if you do not want to dive deeper into the internals of behaviors.
291
+
You do not *need* to know this, but it may help if you run into problems.
292
+
```
293
+
294
+
In Plone, behaviors can be globally enabled on content types at runtime.
295
+
With add-ons, behaviors can even be enabled even on a single content object or for a whole subtree in the content hierarchy.
296
+
297
+
### Interfaces and adapters
298
+
299
+
When a behavior is enabled for a particular object, it will be possible to adapt that object to the behavior's interface.
300
+
Otherwise, when the behavior is disabled, adaptation will fail or falls back to a more generic adapter, if any is registered.
301
+
302
+
A behavior is at least a combination of an interface (also as a form field provider), metadata such as a name, title, and description, and sometimes an adapter factory with a marker interface.
303
+
When a behavior is enabled, an interface is added to the content object to indicate its presence - it now provides the interface.
304
+
305
+
Behaviors without an adapter factory can be used either as a simple marker or to provide additional form fields.
306
+
In this case, adapting a content object with this interface returns the content object itself, because adapting an object that already provides the exact same interface returns the very same object.
307
+
Based on the now-provided interface, i.e specific views can be registered with the content type, or event handlers can be registered to respond to specific actions.
308
+
309
+
In other cases, there is also an adapter factory (usually a class), which will be invoked (initialized) to get an appropriate adapter when requested.
310
+
If an adapter factory is used an explicit marker interface is required.
311
+
312
+
With an adapter factory in place, custom getters and setters for form fields can be implemented, or even new methods i.e. for calculations or to combine data can be added.
313
+
314
+
### Registration
315
+
316
+
Behaviors are registered globally using the <plone.behavior /> {term}`ZCML` directive.
317
+
Internally, this directive registers a named utility that provides `plone.behavior.interfaces.IBehavior`, which contains combined information about the behavior such as its name, interface, factory/marker interface, and metadata.
318
+
319
+
```{seealso}
320
+
The [README file of `plone.behavior`](https://github.com/plone/plone.behavior/blob/master/README.rst) explains the concepts and different ways to register a behavior in detail.
321
+
```
322
+
323
+
### Lookup and provide
324
+
325
+
Plone content objects have logic to look up the behaviors names registered from their types configuration, the Factory Type Information (FTI).
326
+
At runtime, the logic provides the interface (or marker) from the behavior to the object.
327
+
This dynamically provided interface enables the component architecture to react to this new interface by adding additional form fields, bindings events, enabling more specific views, and more.
0 commit comments