Recommended approach for marking a dexterity content type with a new interface
Asked Answered
M

3

5

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).

Marchant answered 18/10, 2011 at 17:26 Comment(1)
Note: your current approach would mark all dexterity container items as providing this marker, not just your type.Ravel
U
4

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.

Upbuild answered 19/10, 2011 at 9:57 Comment(0)
R
2

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

Ravel answered 18/10, 2011 at 23:13 Comment(0)
U
1

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).

Ursuline answered 18/10, 2011 at 18:21 Comment(4)
and I assume grok.implements(IQuickUploadCapable IOtherInterface) would work?Marchant
no, it will not: grok.implements(IQuickUploadCapable, IOtherInterface) will work. Note the comma separating the interfaces.Ursuline
I tried the grok.implements(IQuickUploadCapable) on my class. It didn't work. Just a note, I'm pretty sure that form.schema above should be form.Schema Bottomline, it doesn't work, I get: InvalidInterface: Concrete attribute, __implements_advice_data__Marchant
@DavidBain: github.com/collective/collective.developermanual/blob/master/…Pesek

© 2022 - 2024 — McMap. All rights reserved.