No custom Behavior is needed. The solution with a custom Add and Edit Form does it. I think it's to much for so a seemingly little Problem, but i have no other solution.
<!-- configure.zcml -->
<!-- Register AddForm for Study -->
<adapter
for="Products.CMFCore.interfaces.IFolderish
zope.publisher.interfaces.browser.IDefaultBrowserLayer
plone.dexterity.interfaces.IDexterityFTI"
name="Study"
provides="zope.publisher.interfaces.browser.IBrowserPage"
factory="my.project.browser.forms.StudyAddFormView"/>
<!-- Override EditForm for Study -->
<browser:page
for="my.project.interfaces.IStudy"
name="edit"
class="my.project.browser.forms.StudyEditFormView"
layer="my.project.interfaces.IStudyLayer"
permission="my.project.AddStudyPermission" />
# forms.py
import copy
from plone.dexterity.browser.add import DefaultAddForm
from plone.dexterity.browser.add import DefaultAddView
from plone.dexterity.browser.edit import DefaultEditForm
from plone.z3cform.layout import FormWrapper
def make_field_required(form = None, fieldname=None):
if not fieldname:
return
if not form:
return
_field = None
if 'IPublication.expires' in form.fields.keys():
_field = form.fields.select('IPublication.expires')
else:
for group in form.groups:
if 'IPublication.expires' in group.fields.keys():
_field = group.fields['IPublication.expires']
if _field:
""" create a copy of the field, because all other contenttypes
use the Publication Behavior, and should not changed
"""
_schema_field = copy.deepcopy(_field.field) # shallow copy of an instance
_schema_field.required = True
_field.field = _schema_field
""" Study Add Form"""
class StudyAddForm(DefaultAddForm):
def updateFields(self):
super(StudyAddForm, self).updateFields()
make_field_required(form=self, field='IPublication.expires')
""" Study Add Form View"""
class StudyAddFormView(DefaultAddView):
form = StudyAddForm
""" Study Edit Form"""
class StudyEditForm(DefaultEditForm):
def updateFields(self):
super(StudyEditForm, self).updateFields()
make_field_required(form=self, fieldname='IPublication.expires')
""" Study Edit Form View"""
class StudyEditFormView(FormWrapper):
form = StudyEditForm