Making a schema field of a behavior dependent on the portal_type

Currently working on a behavior that has one field (a checkbox) for all content-types and a second checkbox that applies only to folderish content. Is there a way to make a schema visible/invisible or available/unavailable based on some condition?

https://training.plone.org/5/mastering-plone/behaviors_2.html
Coincidentally have this page open in another tab, I think you want to do something similar as in lines 21 etc... in the interfaces.py example.

class IVoting(model.Schema):
    if not api.env.debug_mode():
        directives.omitted("votes")
        directives.omitted("voted")

Any reason not to use 2 behaviors?

This is a conditional configuration based on the system configuration but not based on e.g. the portal_type of a particular object.

What prevents you from checking portal_type?

IMO the best condition here is the for="" in the behavior directive.

1 Like

The code above is executed once at startup time only. It's not a runtime check.

How about hiding (setting mode to hidden) the field in an custom add/edit-form?

Sorry, not a option.

But my solution works as this: one behavior for folderish content, one for non-folderish content. Defining both behavior using class inheritance is straight forward.