Skip to content

Commit ed374a1

Browse files
committed
order: important things first
1 parent d08fc03 commit ed374a1

File tree

3 files changed

+45
-39
lines changed

3 files changed

+45
-39
lines changed

docs/backend/behaviors.md

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -120,42 +120,6 @@ This looks like so:
120120

121121
After you apply the profile (or uninstall and install the custom add-on), the behavior is available on the Event content type.
122122

123-
## How behaviors work
124-
125-
In Plone, behaviors can be globally enabled on content types at runtime.
126-
With add-ons, behaviors can even be enabled even on a single content object or for a whole subtree in the content hierarchy.
127-
128-
### Interfaces and adapters
129-
130-
When a behavior is enabled for a particular object, it will be possible to adapt that object to the behavior's interface.
131-
Otherwise, when the behavior is disabled, adaptation will fail or falls back to a more generic adapter, if any is registered.
132-
133-
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.
134-
When a behavior is enabled, an interface is added to the content object to indicate its presence - it now provides the interface.
135-
136-
Behaviors without an adapter factory can be used either as a simple marker or to provide additional form fields.
137-
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.
138-
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.
139-
140-
In other cases, there is also an adapter factory (usually a class), which will be invoked (initialized) to get an appropriate adapter when requested.
141-
If an adapter factory is used an explicit marker interface is required.
142-
143-
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.
144-
145-
### Registration
146-
147-
Behaviors are registered globally using the <plone.behavior /> {term}`ZCML` directive.
148-
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.
149-
150-
```{seealso}
151-
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.
152-
```
153-
154-
### Lookup and provide
155-
156-
Plone content objects have logic to look up the behaviors names registered from their types configuration, the Factory Type Information (FTI).
157-
At runtime, the logic provides the interface (or marker) from the behavior to the object.
158-
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.
159123

160124
## Custom behaviors
161125

@@ -315,8 +279,50 @@ plonecli add behavior
315279

316280
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`.
317281

318-
### Further reading on behaviors
282+
### Further reading on working with behaviors
319283

320284
```{seealso}
321285
See the chapter {ref}`training:behaviors1-label` from the Mastering Plone 6 Training.
322286
```
287+
288+
## How behaviors work
289+
290+
```{note}
291+
Skip this section if you do not want to dive deeper into the internals of behaviors.
292+
You do not *need* to know this, but it may help if you run into problems.
293+
```
294+
295+
In Plone, behaviors can be globally enabled on content types at runtime.
296+
With add-ons, behaviors can even be enabled even on a single content object or for a whole subtree in the content hierarchy.
297+
298+
### Interfaces and adapters
299+
300+
When a behavior is enabled for a particular object, it will be possible to adapt that object to the behavior's interface.
301+
Otherwise, when the behavior is disabled, adaptation will fail or falls back to a more generic adapter, if any is registered.
302+
303+
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.
304+
When a behavior is enabled, an interface is added to the content object to indicate its presence - it now provides the interface.
305+
306+
Behaviors without an adapter factory can be used either as a simple marker or to provide additional form fields.
307+
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.
308+
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.
309+
310+
In other cases, there is also an adapter factory (usually a class), which will be invoked (initialized) to get an appropriate adapter when requested.
311+
If an adapter factory is used an explicit marker interface is required.
312+
313+
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.
314+
315+
### Registration
316+
317+
Behaviors are registered globally using the <plone.behavior /> {term}`ZCML` directive.
318+
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.
319+
320+
```{seealso}
321+
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.
322+
```
323+
324+
### Lookup and provide
325+
326+
Plone content objects have logic to look up the behaviors names registered from their types configuration, the Factory Type Information (FTI).
327+
At runtime, the logic provides the interface (or marker) from the behavior to the object.
328+
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.

submodules/volto

Submodule volto updated 99 files

0 commit comments

Comments
 (0)