What is the recommended way to override/alter a registered behavior?
In the document on creating and registering behaviors
The example shows collective.gtags and includes a schema like the one below. It doesn't discuss how a second product might be used to override the registered behavior.
breaking a behavior with a compound of multiple fields into a different behavior with less fields (e.g. when you want to get rid of a field) is not easy.. I tend to create a a new behavior (with code duplication)
it is possible to monkey patch the definition of a field e.g. I injected a validator for the description field using
from plone.autoform.interfaces import IFormFieldProvider
from wildcard.media.behavior import namedfile
from wildcard.media.behavior import valid_audio
from wildcard.media.behavior import IAudio
from rfasite.content import _
from zope.interface import provider
@provider(IFormFieldProvider)
class IRFAAudio(IAudio):
audio_file = namedfile.NamedBlobFile(
title=_(u"Audio File"),
description=u"",
required=False, #this is what we changed from wildcard.media
constraint=valid_audio
)
Oh, and don't forget to update your types that use it.
TTW I unchecked the audio behavior and checked the 'RFA Audio' behavior.
Also edited my gs profile for types that use the behavior:
"""
As a behavior modifying developer
I want to hide the old, unmodified behavior from TTW Dexterity Content settings
(and prominently show the new modified behavior in it's place)
So that TTW settings users don't get confused and choose the wrong behavior
"""
To illistrate, I changed my configure.zcml and got the following screenshot.
<plone:behavior
title="Audio"
description="(modified) Add support for audio fields"
provides="rfasite.content.behaviors.audio.IRFAAudio"
factory="wildcard.media.behavior.Audio"
for="plone.dexterity.interfaces.IDexterityContent"
marker="wildcard.media.interfaces.IAudioEnabled"
/>