Including a vocabulary source in dexterity xml

Is there a TTW way to include one of the common plone vocabularies in Dexterity.
I was hoping it was as simple as doing this in the dexterity modeleditor, but of course it isn't:

<model xmlns:form="http://namespaces.plone.org/supermodel/form" xmlns:i18n="http://xml.zope.org/namespaces/i18n" xmlns:lingua="http://namespaces.plone.org/supermodel/lingua" xmlns:marshal="http://namespaces.plone.org/supermodel/marshal" xmlns:security="http://namespaces.plone.org/supermodel/security" xmlns:users="http://namespaces.plone.org/supermodel/users" xmlns="http://namespaces.plone.org/supermodel/schema">
  <schema>
    <field name="group" type="zope.schema.Choice">
      <source>plone.principalsource.Group</source>
    </field>
  </schema>
</model>

If you want to show vocabulary values in a choice field, you have to use the 'vocabulary' tag:

  <field name="system_type" type="zope.schema.Choice">
    <title i18n:translate="">System Type</title>
    <description i18n:translate="">System Type of this solution</description>
    <vocabulary>plone.principalsource.Group</vocabulary>
    <default></default>
    <required>True</required>
    <readonly>False</readonly>
  </field>

And if you want it to be a multiple selection list with a checkbox field you need to use a "Set" with the relevant widget information:

  <field name="load_type" type="zope.schema.Set" form:widget="z3c.form.browser.checkbox.CheckBoxFieldWidget">
    <title i18n:translate="">Load type</title>
    <description i18n:translate="">Load type used in this project</description>
    <value_type type="zope.schema.Choice">
      <vocabulary>plone.principalsource.Group</vocabulary>
    </value_type>
    <required>False</required>
  </field>
1 Like