interfacezopezope3zcml

Zope3 browser:page multiple interfaces


Let's say I have the following code in my configure.zcml file. I want my class to be implemented for another interface too, let's say Interface2

<browser:page
        for="Interface1"
        class="plone.app.content.browser.reviewlist.FullReviewListView"
        name="full_review_list"
        template="document_full_review_list.pt"
        permission="cmf.ReviewPortalContent" />

How do I declare this in my zcml file?

So long I tried the folowing:

<browser:page
       for="Interface1 Interface2"
       class="plone.app.content.browser.reviewlist.FullReviewListView"
       name="full_review_list"
       template="document_full_review_list.pt"
       permission="cmf.ReviewPortalContent" />

and

<browser:page
       for="Interface1"
       allowed_interface="Interface2"
       class="plone.app.content.browser.reviewlist.FullReviewListView"
       name="full_review_list"
       template="document_full_review_list.pt"
       permission="cmf.ReviewPortalContent" />

Solution

  • You will have to register it twice, once for each interface.

    The name can be the same, without getting a ConfigurationConflictError, since a browserview is a named multi-adapter that adapts both an object providing a specific interface (i.e Interface1 or Interface2) and the request.

    So if the interface that the object is supposed to provide is different for each browserview registration, then there is no conflict.

    <browser:page
            for="Interface1"
            class="plone.app.content.browser.reviewlist.FullReviewListView"
            name="full_review_list"
            template="document_full_review_list.pt"
            permission="cmf.ReviewPortalContent" />
    
    <browser:page
            for="Interface2"
            class="plone.app.content.browser.reviewlist.FullReviewListView"
            name="full_review_list"
            template="document_full_review_list.pt"
            permission="cmf.ReviewPortalContent" />
    

    Conversely, you can have two browserview registrations, for the same object interface (and with the same name), but with the discerning criteria being an interface provided by the request. That's what the layer attribute is for.