Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended approach for marking a dexterity content type with a new interface

While working on a dexterity based project I needed one of my content types to support collective.quickupload by marking it with the IQuickUploadCapable interface.

What I'm currently doing is adding an 'implements' to my configure.zcml file:

`<class class="plone.dexterity.content.Container">      
     <implements interface="collective.quickupload.browser.interfaces.IQuickUploadCapable" />
 </class>`

Since my content type is a Container this works however my first inclination was to use a grok style approach instead of declaring it in ZCML. What's the grok/dexterity way to tell my dexterity content type that it implements an additional interface, or should I stick to the current approach?

Also I tried adding the interface as a behaviour in my profiles/default/types/my.dexterity.content.xml file but this didn't work (I didn't really expect it to as behaviours serve a different purpose).

like image 537
David Bain Avatar asked Oct 18 '11 17:10

David Bain


3 Answers

Sean's answer is good. The other way is to create a behaviour and apply that. You need to register the behaviour with:

<plone:behavior
    title="Quickupload"
    provides="collective.quickupload.browser.interfaces.IQuickUploadCapable"
    />

You can then add 'collective.quickupload.browser.interfaces.IQuickUploadCapable' to your list of behaviours in the FTI.

Your approach using is not good because it means all Container-based Dexterity types get the marker interface, not just your type.

like image 56
optilude Avatar answered Nov 10 '22 18:11

optilude


Why not just subclass IQuickUploadCapable as a mixin after form.Schema in your type interface?

like image 43
sdupton Avatar answered Nov 10 '22 18:11

sdupton


You can not use it as a behaviour because it doesn't claim to be used in that way.

As I read from pypi, is intended to be used in a portlet or in a viewlet.

To add it in a grok style you should:

from collective.quickupload.browser.interfaces import IQuickUploadCapable
from plone.directives import form
class IMyContent(form.schema):
    grok.implements(IQuickUploadCapable)

And that's it!

Be sure that your content type allows files to be added inside it, so is both folderish and it allows files to be added (or it just doesn't restrict to any specific content type).

like image 1
gforcada Avatar answered Nov 10 '22 16:11

gforcada