Add a controlled vocabulary selector field

From FezWiki

Jump to: navigation, search

Contents

HOW TO: Add A Controlled Vocabulary Field

Example XSD Display Tree Structure

Assumes the following structure:              |       Example:
                                              |
 + subloop element                            |        + educationLevels
   + controlled vocabulary (CV) element       |          + dct:educationLevel
     - xsi:type attribute for CV element      |            - xsi:type
   - ID attribute for subloop element         |          - ID


Steps for Adding the Controlled Vocabulary

  1. Create subloop element matching (ex. educationLevels)
    • Set Field Type: XSD Loop Subelement(s)
    • first half:
      • remove all checks
    • second half:
      • check - Value in Tag
  2. Create controlled vocabulary (CV) element matching (ex. dct:educationLevel)
    • Set Field Type: Controlled Vocabulary Selector
    • first half:
      • set - Title (field name to display in enter/edit screens) (ex. Education Level)
      • set - Display Order Priority (controls order of fields in enter/edit screens)
      • check - Enabled in Form?
      • check - Show in View Details?
    • second half:
      • check - Value in Tag
    • CV specific section:
      • select Controlled Vocabulary (ex. NSDL Education Level)
      • select Minimum Selectable Branch Level:
        • Top Parent Branch to allow first level items to be selected (most common),
        • OR First Child Branch to start selection at second level items (ex. used when more than one CV can fill the field, where the Top Parent Branch is the list of controlled vocabularies instead of the list of items)
      • select Save CVO value or ID?: Value
  3. Edit subloop element matching (ex. educationLevels)
    • Manage XSD Looping Subelements section:
      • set XSD Subelement Loop Title: use CV element name + Loop (ex. educationLevel Loop)
      • set Subelement Loop Type: Loop on Element or Attribute
      • set Loop on Matching Field: select the XSD where the CV element is defined
      • set Loop on Matching Field: select the CV element (ex. !educationLevels!dct:educationLevel)
      • set Indicator: Indicator Off
      • set Indicator Value: leave blank
      • set Order: 1 (!!! important - won't be added if this is left blank !!!)
  4. Connect CV element matching to subloop element XSD Loop manually through php MyAdmin
    • in Table: xsd_loop_subelement
      • find row (most likely the last row) where xsdsel_title=XSD Subelement Loop Title (ex. educationLevel Loop)
      • write down...
        • xsdsel_id
        • xsdsel_attribute_loop_xsdmf_id
    • in Table: xsd_display_matchfields
      • find row where xsdmf_id==xsdsel_attribute_loop_xsdmf_id (most likely one of the last few rows)
        • record xsdmf_xdis_id
      • find row where xsdmf_xdis_id==recorded xsdmf_xdis_id AND xsdmf_element==xpath to CV element (ex. xsdmf_element==!acessRights!dct:educationLevel) (Might be easier to find looking for the title... ex. Education Level)
        • record xsdmf_id
        • edit and set xsdmf_xsdsel_id (3rd field) to xsdsel_id recorded previously
  5. Verify manually set connection is correct (Editing Displays in OnRamp)
    • Click CV element
      • Verify that XSDMF ID==xsdmf_id recorded previously
      • Click link and verify that this is the CV element defined with Field Type: Controlled Vocabulary Selector
  6. Create xsd:type attr matching for CV element (create only if needed - not all CV have a xsd:type)
    • Set Field Type: Hidden Static Text
    • first half:
      • remove all checks
    • second half:
      • check - Value in Tag
    • Hidden Static Text section:
      • set Static Text: value for xsd:type (ex. nsdl_dc:NSDLEdLevel)
  7. Create ID attr matching for 'subloop element (REQUIRED: to hold ID from CV)
    • Set Field Type: XSDMF ID Reference
    • first half:
      • check - Enabled in Form? (Not sure why this is checked, but it was checked for all CVs. I think it is ignored.)
      • check - Show in View Details? (Not sure why this is checked, but it was checked for all CVs. I think it is ignored.)
    • second half:
      • check - Value in Tag
    • XSDMF ID Reference section
      • select the XSD where the CV element is defined
      • select the CV element (ex. !educationLevels!dct:educationLevel)
      • set Save reference value or ID?: ID


What gets generated in the datastream?

Example of Elements Generated:

 <educationLevels ID="466518">
   <dct:educationLevel xsi:type="nsdl_dc:NSDLEdLevel">Elementary School</dct:educationLevel>
 </educationLevels>
 <educationLevels ID="466519">
   <dct:educationLevel xsi:type="nsdl_dc:NSDLEdLevel">Early Elementary</dct:educationLevel>
 </educationLevels>
 <educationLevels ID="466523">
   <dct:educationLevel xsi:type="nsdl_dc:NSDLEdLevel">Upper Elementary</dct:educationLevel>
 </educationLevels>
   

FIX: Controlled Vocabulary doesn't start at the selected controlled vocabulary for a field

NOTE: At the writing of this document, the code that allows a field to specify which controlled vocabulary has the values for the field is not working. Everytime Add Subject is selected for a controlled vocabulary field, the list of all available controlled vocabularies appears on the first screen.

To fix this...

Fix entry screen:

  • Edit /workflow/enter_metadata.php and make the following change...
OLD:

 if (($dis_field["xsdmf_html_input"] == 'contvocab')
          || ($dis_field["xsdmf_html_input"] == 'contvocab_selector')) {
  //    $xsd_display_fields[$dis_key]['field_options'] = @$cvo_list['data'][$dis_field['xsdmf_cvo_id']];
  }

 NEW:
 
  if (($dis_field["xsdmf_html_input"] == 'contvocab')
          || ($dis_field["xsdmf_html_input"] == 'contvocab_selector')) {
  //    $xsd_display_fields[$dis_key]['field_options'] = @$cvo_list['data'][$dis_field['xsdmf_cvo_id']];
        $xsd_display_fields[$dis_key]['cvo_id'] = $dis_field['xsdmf_cvo_id'];
  }
  • Edit /templates/en/workflow/enter_metadata.tpl.html


OLD:

 {elseif $xsd_display_fields[i].xsdmf_html_input == 'contvocab_selector' && $xsd_display_fields[i].xsdmf_enabled == 1}

          <tr id="tr_list_{$list[i].xsdmf_id}_0" valign="top">
            <td width="200" bgcolor="{$cell_color}" class="default">
              <b>{$xsd_display_fields[i].xsdmf_title} {if $xsd_display_fields[i].xsdmf_required == 1} * {/if}</b><br />
            </td>
             {assign var="field_name" value="xsd_display_fields["|cat:$xsd_display_fields[i].xsdmf_id|cat:"][]"}
            <td bgcolor="{$light_color}">
              <select id="xsd_display_fields_{$xsd_display_fields[i].xsdmf_id}_0" multiple size="10" class="default" name="xsd_display_fields[{$xsd_display_fields[i].xsdmf_id}][]">
              </select>
              {include file="error_icon.tpl.html" field=$field_name}						
              <input class="default" type=button value="Add Subject" onclick = 
                "javascript:small_window('{$rel_url}cv_selector.php?cvo_id=&
                form=wfl_form1&element=xsd_display_fields_{$xsd_display_fields[i].xsdmf_id}_0&
                xsdmf_cvo_min_level={$xsd_display_fields[i].xsdmf_cvo_min_level}');">
              <input class="default" type=button value="Remove Subject" onclick =
                " javascript:deleteSelectedItemsFromList(xsd_display_fields_{$xsd_display_fields[i].xsdmf_id}_0);">
           </td>
          </tr>				

 NEW:
 
  {elseif $xsd_display_fields[i].xsdmf_html_input == 'contvocab_selector' && $xsd_display_fields[i].xsdmf_enabled == 1}

          <tr id="tr_list_{$list[i].xsdmf_id}_0" valign="top">
            <td width="200" bgcolor="{$cell_color}" class="default">
              <b>{$xsd_display_fields[i].xsdmf_title} {if $xsd_display_fields[i].xsdmf_required == 1} * {/if}</b><br />
            </td>
             {assign var="field_name" value="xsd_display_fields["|cat:$xsd_display_fields[i].xsdmf_id|cat:"][]"}
            <td bgcolor="{$light_color}">
              <select id="xsd_display_fields_{$xsd_display_fields[i].xsdmf_id}_0" multiple size="10" class="default" name="xsd_display_fields[{$xsd_display_fields[i].xsdmf_id}][]">
              </select>
              {include file="error_icon.tpl.html" field=$field_name}						
              <input class="default" type=button value="Add Subject" onclick = 
                "javascript:small_window('{$rel_url}cv_selector.php?cvo_id={$xsd_display_fields[i].cvo_id}&
                form=wfl_form1&element=xsd_display_fields_{$xsd_display_fields[i].xsdmf_id}_0&
                xsdmf_cvo_min_level={$xsd_display_fields[i].xsdmf_cvo_min_level}');">
              <input class="default" type=button value="Remove Subject" onclick =
                " javascript:deleteSelectedItemsFromList(xsd_display_fields_{$xsd_display_fields[i].xsdmf_id}_0);">
           </td>
          </tr> 

Fix edit screen:

  • Edit /include/class.record_edit_form.php
    • This functionality appears to not exist at all in the current revision of this class. It was in older revisions.
    • At the very end of function fixDisplayFields()...
OLD:

          }
      }
  }
  
  function fixDetails(&$details)
  {

  
 NEW:
 
          }   
          if (($dis_field["xsdmf_html_input"] == 'contvocab')
                 || ($dis_field["xsdmf_html_input"] == 'contvocab_selector')) {
//           $xsd_display_fields[$dis_key]['field_options'] = @$cvo_list['data'][$dis_field['xsdmf_cvo_id']];
             $xsd_display_fields[$dis_key]['cvo_id'] = $dis_field['xsdmf_cvo_id'];
          }
      }
  }
  
  function fixDetails(&$details)
  {


  • Edit /templates/en/workflow/edit_metadata_helpers/field_contvocab_selector.tpl.html
OLD:

 <select id="xsd_display_fields_{$xsd_display_fields[i].xsdmf_id}_0" multiple size="10" class="default" 
      name="{$field_name}">
      {if $details[$temp_fld_id]}
        {html_options options=$details[$temp_fld_id]}
      {/if}
  </select>
  {include file="error_icon.tpl.html" field=$field_name}
  <input class="default" type=button value="Add Subject" onclick = 
    "javascript:small_window('{$rel_url}cv_selector.php?cvo_id=&
    form=wfl_form1&element=xsd_display_fields_{$xsd_display_fields[i].xsdmf_id}_0&
    xsdmf_cvo_min_level={$xsd_display_fields[i].xsdmf_cvo_min_level}');">
  <input class="default" type=button value="Remove Subject" onclick =
    " javascript:deleteSelectedItemsFromList(xsd_display_fields_{$xsd_display_fields[i].xsdmf_id}_0);">

 NEW:
 
  <select id="xsd_display_fields_{$xsd_display_fields[i].xsdmf_id}_0" multiple size="10" class="default" 
      name="{$field_name}">
      {if $details[$temp_fld_id]}
        {html_options options=$details[$temp_fld_id]}
      {/if}
  </select>
  {include file="error_icon.tpl.html" field=$field_name}
  <input class="default" type=button value="Add Subject" onclick = 
    "javascript:small_window('{$rel_url}cv_selector.php?cvo_id={$xsd_display_fields[i].cvo_id}&
    form=wfl_form1&element=xsd_display_fields_{$xsd_display_fields[i].xsdmf_id}_0&
    xsdmf_cvo_min_level={$xsd_display_fields[i].xsdmf_cvo_min_level}');">
  <input class="default" type=button value="Remove Subject" onclick =
    " javascript:deleteSelectedItemsFromList(xsd_display_fields_{$xsd_display_fields[i].xsdmf_id}_0);">
Powered by MediaWiki
GNU Free Documentation License 1.2