You are here

function microdata_form_field_ui_field_edit_form_submit in Microdata 7

Submit callback; saves field mapping in both UIs.

2 string references to 'microdata_form_field_ui_field_edit_form_submit'
microdata_bundle_mapping_form in ./microdata.admin.inc
Form builder helper function.
microdata_form_field_ui_field_edit_form_alter in includes/microdata.form_alter.inc
Implements hook_form_FORM_ID_alter().

File

includes/microdata.form_alter.inc, line 250
Provides inline structured data using Microdata format.

Code

function microdata_form_field_ui_field_edit_form_submit($form, &$form_state) {
  $entity_type = isset($form_state['#entity_type']) ? $form_state['#entity_type'] : $form['instance']['entity_type']['#value'];
  $bundle = isset($form_state['#bundle_type']) ? $form_state['#bundle_type'] : $form['instance']['bundle']['#value'];
  $values = $form_state['values'];
  $mapping = _microdata_load_mapping($entity_type, $bundle);
  foreach ($values['microdata']['fields'] as $field_name => $field_values) {
    $subfields = _microdata_get_field_properties($entity_type, $bundle, $field_name);

    // If the field itself is microdata enabled, add the mapping for the field.
    if (isset($field_values['field'])) {
      $mapping[$field_name] = array(
        '#itemprop' => drupal_explode_tags($field_values['field']['itemprop']),
      );

      // If the field should be handled as an item, add the is_item flag to the
      // field's mapping and save the itemtype.
      // @todo Consider adding the itemid.
      if (!empty($field_values['field']['is_item'])) {
        $mapping[$field_name]['#is_item'] = TRUE;
        if (isset($field_values['field']['item_fieldset']['itemtype'])) {
          $mapping[$field_name]['#itemtype'] = drupal_explode_tags($field_values['field']['item_fieldset']['itemtype']);
        }
        else {
          $mapping[$field_name]['#itemtype'] = array();
        }
      }
      else {
        $mapping[$field_name]['#is_item'] = FALSE;
      }
    }

    // Add the mappings for field properties.
    foreach ($subfields as $subfield_name => $subfield) {
      $element = array(
        '#itemprop' => drupal_explode_tags($field_values['subfields'][$subfield_name]['itemprop']),
      );

      // If the subfield contains an item, save an itemtype scoped to this item.
      // @todo Consider whether a subfield should ever be able to save an item.
      if (isset($field_values[$subfield_name]['item_fieldset']['itemtype'])) {
        $element['#itemtype'] = $field_values['subfields'][$subfield_name]['item_fieldset']['itemtype'];
      }
      else {
        $element['#itemtype'] = '';
      }
      $mapping[$field_name][$subfield_name] = $element;
    }
  }
  microdata_save_mapping($entity_type, $bundle, $mapping);
}