Schema Extender with IBrowserLayerAwareExtender applied to all Plone sites

I've got a product installed in one Plone Site, this product change the visibility of a field of the Event content type.

It use IBrowserLayerAwareExtender to restrain the change to only the Plone Site where the product is installed.

This work on the development server on which buildout is made with the develop.cfg option, but in production, the layer is not respected, and all others Plone Site have this change.

Here is the code:

schemaextender.py:

    class EventModifier(object):
    """
    Masque certains champs inutiles pour le projet
    """
    implements(ISchemaModifier, IBrowserLayerAwareExtender)
    adapts(IATEvent)
    layer = IBswMonasticLayer

    def __init__(self, context):
        self.context = context

    # noinspection PyMethodMayBeStatic
    def fiddle(self, schema):
        """

        :param schema:
        :return:
        """
        schema['attendees'].widget.visible = {'edit': 'invisible', 'view': 'invisible'}
        schema['location'].widget.label = _(u'Adresse')
        return schema

configure.zcml:

<adapter for="Products.ATContentTypes.interface.IATEvent"
             provides="archetypes.schemaextender.interfaces.ISchemaModifier"
             factory=".schemaextender.EventModifier"
             name="bsw.monastic.schemaextender.EventModifier"/>

Is it a bug or am I missing something ?

No idea why is not working since I never used IBrowserLayerAwareExtender myself.

Have you double checked the layer is not present in the other plone sites? I.e: you installed the product to the other sites and the uninstall profile does not remove the layer.

An alternative way to run an adapter conditionally is to write the condition yourself like:

def fiddle(self, schema):

    if not IBswMonasticLayer.providedBy(self.context.REQUEST):
        return None

     # Method
1 Like

just some thoughts:

the for attribute is redundant (already given by adapts(IATEvent) in schemaextender.py (but this should not be a problem)

i often had the opposite problem (extender does not work) and these checkes helped me there

typical pitfall i experienced: make sure your IBswMonasticLayer extends zope.publisher.interfaces.browser import IDefaultBrowserLayer
is installed via profiles/browserlayer.xml with a name that is also used in your portal_skins current skin.

create a view named test-skins that lists all interfaces implemented by the request. your other portals w/o your package installed should not list IBswMonasticLayer (if not - you're doing something wrong when registering the layer or did not uninstall cleanly as @csanahuja suggested)

to be able to override views of other packages, i sometimes needed to subclass these packages browserlayer(s) to make sure this layer is more specific. (maybe this is needed too in case plone.app.event is involved with schemaextenders here too (as you extend IATEvent here)

from plone.app.event.interfaces import IBrowserLayer
class IThemeSpecific(IBrowserLayer):
    """A layer specific to the my package

    subclass plone.app.event's browserlayer to be able to override views
    registered there
    """

    pass

i know this mostly does not address your problem (as your extender shows up on plone sites that should not have the browserlayer) because i misunderstood your question initially. sorry

nevertheless i posted this as it might help others with schemaextender issues.

Thanks, that works now !

Plone Foundation Code of Conduct