Starting in Plone 3, Archetypes provides an opportunity for third-party code to modify schemas on the fly. It exposes a point of adaptation here, in BaseObject
, one of the most foundational subclasses of every content type:
1 class BaseObject(Referenceable):
2 # (some code omitted here)
3
4 def Schema(self):
5 """Return a (wrapped) schema instance
6 for this object instance.
7 """
8 schema = ISchema(self)
9 return ImplicitAcquisitionWrapper(schema, self)
Line 8 is where the magic happens. This line has always determined the schema, but the ISchema
adapter lookup—which essentially says "Find me the preferred chunk of code that knows how to compute schemas."—is new. We'll discuss adaptation itself shortly, but the upshot is that third-party code has the opportunity to plug in its own ways of determining schemas—in our case, to say "Insert a few new fields here."
Without further clever tricks, there's only room for one piece of code to plug in a schema-determiner...