Customizing content object form behavior
Purpose
You have created a new content type and you want to tune up it a bit
- Go to some other page instead of view on a successful save
- Customize how view and edit widgets are rendered
Prerequisities
You have created Archetypes content type as a Python product. You are aware how Plone skin layers function and able to add a new skin layer where your customized templates go.
Step by step
Plone uses an underlying subsystem called CMFFormController to manage HTML form submissions. Due to its heritage, this subsystem is quite complex and has several different types of parts
- .pt page template files to render normal HTML pages
- .cpt page template files to render HTML forms with traversing data
- .py Python Script files to add view logic
- .cpy Python Script files to add custom traversing logic
- .metadata text files in INI format to describe traversing and validation
- .xml GenericSetup files to register various parts during the product installation
.py and .cpy files are not Python modules. They are Python script snippets which are executed inside a security manager i.e. the user executing the script cannot break out of the sandbox even accidentally.
Since the controlling is not done in pure Python, but using several custom file formats managing and debugging CMFFormController can be challenging.
Customizing view page
- Copy-paste base_view.pt from
Customizing edit page
Customizing traversing
A very complex traversing chain is used during the object save. Here I cover all the steps. Versioning steps are optional and available only for objects supporting versioning.
- mycustomcontent_edit.cpt - Render HTML form, based on atct_edit.cpt
- mycustomcontent_edit.metadata - Decide traversing after the form has been submitted
- validate_atct - Execute form validators
- success -> 3 (if versioning is used)
- success -> 4
- failure -> 1
- add_reference -> last_referer - Custom hook for reference edit field
- (update_version_before_edit) - optionally set versioning save point
- success -> 4
- mycustomcontent_content_edit.cpy - Call content_edit_impl.py
- mycustomcontent_content_edit.metadata
- validate_base - Validate fields after save
- success -> 6
- mycustomcontent_validate_integrity - Check that references are ok after save
- success -> 7
- success -> update_version_on_edit (if versioning is used)
- failure -> 1
- mycustomcontent_view
Further information
Some existing examples
- Remember product cmfformcontroller.xml
