Overriding the form controler script for AT content

Just like the edit form or the view page can be overriden for an AT type, so can the form controler script that would be called by the form. This recipe is lifted from SignupSheet (which I think got an inspiration from POI):

The form controler script (mytype_post.cpy):

##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind state=state
##bind subpath=traverse_subpath
##parameters=
##title=Do something
##

#do something here, like for example, changing the workflow status of the object

return state

The metadata file (mytype_post.cpy.metadata):

[actions]
action.success=redirect_to:string:${folder_url}/thank_you_message
action.failure=traverse_to_action:string:edit

And now, the magic happens in Extensions/Install.py

def addFormControllerAction(self, out, controller, template, status, 
                                contentType, button, actionType, action):
    """Add the given action to the portalFormController"""
    controller.addFormAction(template, status, contentType,
                                button, actionType, action)
    print >> out, "Added action %s to %s" % (action, template)

def Install(portal):
    controller = getToolByName(self, 'portal_form_controller')
    addFormControllerAction(self, out, controller, 'validate_integrity',
                            'success', 'MyType', None, 'traverse_to', 'string:mytype_post')

A bit of explanation: validate_integrity is the last script called in the normal AT edit process. The install script will add another transition, so after the validate_integrity is executed, next comes the mytype_post script to be executed.

Comments