[SOLVED] Plone supermodel XML with inline key-value pairs

The element element inside a supermodel XML allows us to specify the value of a vocabulary.

However is is possible to define the token separately from the title?


  <field name="type-activiteit" type="zope.schema.Choice" easyform:validators="" easyform:THidden="">
                              <description>Het soort activiteit wordt enkel hier vermeld (niet in de titel). Zo kunnen bezoekers een selectie maken op de verschillende types (bv. alle lezingen).</description>
                              <title>Soort activiteit</title>
                              <required>True</required>
                              <values>                 
 <element>|--Kies een optie--</element>
                  <element>Alumni-event</element>
                  <element>Academische zitting</element>
                  <element>Benefiet</element>
                  <element>Concert</element>
                  <element>Debat</element>
                  <element>Excursie</element>
                  <element>Filmvoorstelling</element>
                  <element>Happening</element>

                  <element>Workshop</element>
           </values>
    </field>

The reason is PFG -> EasyForm migration where collective.jsonify exports a vocabulary as

    "fgVocabulary": [
        "nl|Nederlands",
        "fr|Frans",
        "en|Engels",
        "de|Duits",
        "es|Spaans",
        "it|Italiaans",
        "ru|Russisch"
    ],

... and this has to be mapped somehow into the supermodel XML.

registry.xml lets you do this...

  <record name='mdb_theme.ColorTypeList'>
      <field type='plone.registry.field.Dict'>
        <title>Custom color name types</title>
        <description>(token, translationmessage)</description>
        <key_type name='key' type='plone.registry.field.ASCIILine'>
          <title>unique id (token)</title>
        </key_type>
        <value_type name='value' type='plone.registry.field.TextLine'>
          <title>value (title)</title>
        </value_type>
      </field>
      <value purge="False">
        <element key='colorlist_pnz_default'>Nur PNZ Standard Farben</element>
        <element key='colorlist_pnz_czech'>Powered by PNZ - Tsjechei</element>
      </value>
    </record>
1 Like

It might be enough to just add 'key':

<element key="a">Academische zitting</element>

I'd guess you have to define field as a zope.schema.Dict and give it names for key_type and value_type as well.

I tried something… not sure if it is of any use:

Using the key attribute works. SOLVED

you're right :muscle:

both single and multiple choice fields can use a key/value pair:

    <field name="multiple_choice" type="zope.schema.Set">
      <description/>
      <required>False</required>
      <title>multiple choice</title>
      <value_type type="zope.schema.Choice">
        <values>
          <element key="aaa">choice 1</element>
          <element key="bbb">choice 2</element>
        </values>
      </value_type>
    </field>
    <field name="single_choice" type="zope.schema.Choice">
      <description/>
      <required>False</required>
      <title>single choice</title>
        <values>
          <element key="aaa">choice 1</element>
          <element key="bbb">choice 2</element>
        </values>
    </field>
1 Like