Widget overrides -- or why does plone.app.z3cform define marker interfaces for date fields?

plone.app.z3cform defines marker interfaces for date/datetime fields. I am assuming this is for making mockup widget lookup specificity easier? But what happens when an add-on wants to override one of the default (mockup/plone) widgets (see note below)?

IDateField and IDatetimeField interfaces are defined in:

plone.app.z3cform.interfaces (for Plone 5).

and

plone.app.z3cform.widget (for Plone 4 using plone.app.widgets 1.x).

These appear to be earlier in the specification resolution order in the component registry than zope.schema.interfaces.IDate and zope.schema.interfaces.IDatetime.

The implication of this that is not documented, but should be:

To override a widget defined in plone.app.z3cform/plone.app.widgets, one must declare IFieldWidget factory/adapters for plone.app.z3cform.interfaces.IDateField or plone.app.z3cform.interfaces.IDatetimeField, not merely zope.schema.interfaces.IDate or zope.schema.interfaces.IDatetime, and must also:

  • Ensure your add-on's browser layer interface subclasses z3c.form.interfaces.IFormLayer;
  • Ensure your widget factory/adapter declares that it adapts IDateField and your add-on's browser layer interface;

Both of the above conditions are sufficent to ensure that component lookup for your widget, on a site with your add-on installed, is more specific than the registration for the default widgets provided.

This peculiarity seems isolated to just these two field types (I am not sure why that is)?

I am happy to document this on docs.plone.org somewhere if anyone has suggestions on what page/section I should document this in?

Sean