plonedexterity

How to add a condition to make a Dexterity type addable?


The Dexterity FTI has an option to select a permission as an "AddPermission" for a type, but I am looking for a way to require some potentially complex logic to resolve true before allowing the type to be added to a container. In my particular example, I won't to allow only X number of this content in any given container. If I could subclass a method that was, say, "isAddable" or something that would be great, but I don't see any method off hand that does this. Perhaps this isn't possible because the class object is not initiated yet, so it can't call any methods, but maybe the FTI itself has something?

I've thought of two other options. In my case, since the container is also a custom content type, I can override its allowedContentTypes method. I'd rather not rely on the container to do this check though. Another option is to override the addable_types method in plone.app.content.browser.folderfactories.FolderFactoriesView. Is there a better approach?

This is in Plone 4.3


Solution

  • unfortunately there is no such thing as "addable_expression" in the fti.

    i think overriding FolderFactoriesView won't do the trick - smart users still can call ${folder_url}/++add++your.type.

    a custom implementation of allowedContentTypes for your folderish type sounds like a good solution to me.

    another option would be to add an event handler (dunno which event would fit though - maybe zope.lifecycleevent.IObjectCreatedEvent is just fine) that raises an error in case your condition is not met. (users would still see "add / yourtype" menu but get an error - so this should be combined with the custom FolderFactoriesView)