The schema of my custom dexterity content type disallow the edition of some fields, and show them as a label followed by value. I'd like a different rendering for those values, as well as for other parts of the edit form.
How to fully customize an edit form (without modifying a schema)?
<!-- configure.zcml e.g. in the browser module
<!-- Override EditForm for Collection -->
<browser:page
for="plone.app.contenttypes.interfaces.ICollection"
name="edit"
class=".forms.CollectionEditFormView"
layer="your.addon.interfaces.IMyAddonLayer"
permission="cmf.ModifyPortalContent" />
# forms.py
from plone.dexterity.browser.edit import DefaultEditForm
from plone.dexterity.browser.edit import DefaultEditView
class CollectionEditForm(DefaultEditForm):
""" Collection Edit Form"""
# render the form without tabs
enable_form_tabbing = False
# hold all widget from all fieldsets
allWidgets = {}
def updateFields(self):
super(CollectionEditForm, self).updateFields()
# do your stuff
self.allWidgets['IPublication.effective'].mode = DISPLAY_MODE
def updateWidgets(self):
super(MyCTEditForm, self).updateWidgets()
def update(self):
super(CollectionEditForm, self).update()
# do your stuff
self.collectWidgets()
def collectWidgets(self):
# all widgets from the schema
# the default fieldset
for name, widget in self.widgets.items():
self.allWidgets.update({name:widget})
# all widgets from the behavior schemas
# additional fieldset
for group in self.groups:
for name, widget in group.widgets.items():
self.allWidgets.update({name:widget})
class CollectionEditFormView(DefaultEditView):
""" Collection Edit Form View """
form = CollectionEditForm
super(MyCTEditForm, self).updateWidgets()
should be : super(CollectionEditForm, self).updateWidgets()
Specifying a layer is not working (I get a "This page does not seem to exist…" page); it works without it. Is it always required? If so, how to declare it correctly?
Also, self.allWidgets['IPublication.effective'].mode = DISPLAY_MODE
results with KeyError: 'IPublication.effective'
So what I get now with this new form is exactly like what I had before. In order to change the rendering of the widgets, I have to customize something (at "# your stuff")?; what and how?
Isn't there a way to override a template to display the form exactly as needed?
Answering to myself:
What I needed was to add : template = ViewPageTemplateFile('templates/my_edit_template.pt')
at the end of CollectionEditForm
Then I based my template on item.pt from plone.app.dexterity
Edit: In the template, I use metal:use-macro="context/@@ploneform-macros/titlelessform"
and I override the slots defined in macros.pt (from plone.z3cform)