Current

This document is valid for the current version of Plone.

Add views for content types

by Plone Documentation Team last modified Jan 05, 2010 09:02 PM
In Plone 4, every Factory Type Information object in portal_types will have an additional, optional property which can be set to a TALES expression to provide the URL of a view that will be shown when the user chooses to add an object of this particular type from the "Add" menu in Plone.

This property has the title Add view URL (expression) and the internal id add_view_expr.

For example, if you have a custom add form called @@add-my-content, you could set this expression to string:${folder_url}/@@add-my-content. (Note that the view in this case needs to be registered for the folder type, not for the type being created.)

If this property is not set, Plone will fall back on the createObject script as before, which in turn will create the object or invoke the portal_factory tool. This is likely to be the correct behaviour for most Archetypes-based content objects.

In Plone 3, it was possible to have an add view be invoked by registering a view for the IAdding view (aka the + view) that had the same name as the factory property specified in the Factory Type Information. For example, a type with a factory of my.type could be accompanied by a view with the name 'my.type' registered for the IAdding interface. This would be found and preferred over the createObject script, and was sometimes used with non-Archetypes content.

In Plone 4, this association needs to be made explicit. (This is mainly for performance reasons.) To use such an add view, you need to set the add_view_expr property to invoke it, e.g. string:${folder_url}/+/my.type.

Finally, note that the IAdding (+) view is falling out of favour. It will continue to work indefinitely, but most people these days prefer to register a simple view (e.g. @@add-my-content) for the folder type (e.g. the IFolderish interface from Products.CMFCore.interfaces) which constructs and adds the content in reaction to a valid form submission. This is because the "view-on-a-view" concept used by IAdding can be confusing and requires special handling in certain places (e.g. some vocabulary factories) to deal with the fact that view.context is another view, not a content object. The add form base classes in zope.formlib still use the IAdding view, but z3c.form comes with an add form base class that acts as a simple view.