The default Dexterity add form registers the save button and handler thus:
@button.buttonAndHandler(_('Save'), name='save')
def handleAdd(self, action):
data, errors = self.extractData()
if errors:
self.status = self.formErrorsMessage
return
obj = self.createAndAdd(data)
if obj is not None:
# mark only as finished if we get the new object
self._finishedAdd = True
IStatusMessage(self.request).addStatusMessage(
self.success_message, "info"
)
How can I override (just) the handler with my own? I'd prefer to just register some adapter, but if registering a subclassed custom form is the only option, then that's acceptable, too.
According to what you need, it could be enough to just override createAndAdd, but generally speaking you could do something similar:
In particular you can play with the handler of the original class doing something similar (line 50):
Of course you can add your custom code before and after the base_handler invocation.
In addition you can also play with the updateActions method (see line 28).
Remember that when you want to ovverride buttons you have to override all of them.
Another tip is that, in order to customize your ++add++your.portal.type traverser you have to register an homonymous named adapter:
See http://docs.plone.org/develop/plone/content/dexterity.html#custom-add-form-view