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
+23-23Lines changed: 23 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,7 @@ This allows items of this content type to gain the additional functionality prov
34
34
35
35
Overall, behaviors are an important part of the Plone content management system and allow for powerful customization and extensibility of content objects.
36
36
37
+
37
38
## Built-in behaviors
38
39
39
40
| short name | Title | Desription |
@@ -119,39 +120,38 @@ After you apply the profile (or uninstall and install the custom add-on), the be
119
120
120
121
## How behaviors work
121
122
122
-
At the most basic level, a behavior is like a conditional {term}`adapter`.
123
-
For a content type, the default condition is, "is this behavior listed in the behaviors property in the FTI?"
124
-
But the condition itself is an adapter; in rare cases, this can be overruled.
125
-
When a behavior is enabled for a particular object, it will be possible to adapt that object to the behavior's interface.
126
-
If the behavior is disabled, adaptation will fail.
123
+
In Plone, behaviors can be globally enabled on content types at runtime.
124
+
With add-ons, behaviors can even be enabled even on a single content object or for a whole subtree in the content hierarchy.
127
125
128
-
A behavior consists at the very least of an interface and some metadata, namely a name, title, and description.
129
-
This is also called a schema-only interface.
126
+
### Interfaces and adapters
127
+
128
+
When a behavior is enabled for a particular object, it will be possible to adapt that object to the behavior's interface.
129
+
Otherwise, when the behavior is disabled, adaptation will fail or falls back to a more generic adapter, if any is registered.
130
130
131
-
In other cases, there is also a factory, akin to an adapter factory, which will be invoked to get an appropriate adapter when requested.
132
-
This is usually just a class that looks like any other adapter factory, although it will tend to apply to Interface, IContentish, or a similarly broad context.
131
+
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.
132
+
When a behavior is enabled, an interface is added to the content object to indicate its presence - it now provides the interface.
133
133
134
-
Behaviors can specify a marker interface, which will be directly provided by instances for which the behavior is enabled.
135
-
If you want to conditionally enable event handlers or view components, they can be registered for this marker interface.
134
+
Behaviors without an adapter factory can be used either as a simple marker or to provide additional form fields.
135
+
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.
136
+
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.
136
137
137
-
Some behaviors have no factory.
138
-
In this case, the behavior interface and the marker interface must be the same.
138
+
In other cases, there is also an adapter factory (usually a class), which will be invoked (initialized) to get an appropriate adapter when requested.
139
+
If an adapter factory is used an explicit marker interface is required.
139
140
140
-
If a factory is given a marker interface different from the behavior interface must be declared!
141
+
### Registration
141
142
142
-
Behaviors are registered globally, using the `<plone.behavior />` ZCML directive.
143
-
This results in, among other things, a named utility providing `plone.behavior.interfaces.IBehavior` being registered.
144
-
This utility contains various information about the behavior, such as its name, title, interface, and (optional) factory and marker interface.
143
+
Behaviors are registered globally using the <plone.behavior /> {term}`ZCML` directive.
144
+
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.
145
145
146
-
The utility name is the name attribute of the behavior directive.
147
-
Historically the full dotted name to the behavior interface is registered as its name, too, but this usage is discouraged.
146
+
### Lookup and provide
148
147
148
+
Plone content objects have logic to look up the behaviors names registered from their types configuration, the Factory Type Information (FTI).
149
+
At runtime, the logic provides the interface (or marker) from the behavior to the object.
150
+
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.
149
151
150
-
Behaviors are named adapters.
151
-
They adapt an interface, for which they are registered and they provide another interface with new functionality such as attributes and methods.
152
+
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.
152
153
153
-
Content types transparently look up the behaviors registered for a content type.
154
-
If a behavior provides new attributes, it is provided as an attribute of the adapted object.
154
+
### Additional information
155
155
156
156
```{seealso}
157
157
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.
0 commit comments