You are here

function sf_prematch_edit_form in Salesforce Suite 7

Same name and namespace in other branches
  1. 6.2 sf_prematch/sf_prematch.admin.inc \sf_prematch_edit_form()
  2. 7.2 sf_prematch/sf_prematch.admin.inc \sf_prematch_edit_form()
1 string reference to 'sf_prematch_edit_form'
sf_prematch_menu in sf_prematch/sf_prematch.module
Implementation of hook_menu().

File

sf_prematch/sf_prematch.admin.inc, line 55
Admin functions for sf_prematch module.

Code

function sf_prematch_edit_form(&$form_state, $fieldmap) {

  // Load the fieldmap from the database.
  $map = salesforce_api_fieldmap_load($fieldmap);

  // Return to the admin page if the fieldmap did not exist.
  if (empty($map)) {
    drupal_set_message(t('That fieldmap does not exist.'), 'error');
    drupal_goto(SALESFORCE_PATH_FIELDMAPS);
  }

  // Return to the admin page if the fieldmap has no mapped fields.
  if (empty($map['fields'])) {
    drupal_set_message(t('That fieldmap exists, but does not have any fields.'), 'error');
    drupal_goto(SALESFORCE_PATH_FIELDMAPS);
  }

  // Load the prematch from the database.
  $prematch = sf_prematch_match_by_load($fieldmap);
  $form = array();

  // Add the index to the form array.
  $form['fieldmap_index'] = array(
    '#type' => 'value',
    '#value' => $fieldmap,
  );

  // Set flag for use in deciding where to redirect to on form submit.
  $is_new = $form['new_prematch'] = array(
    '#type' => 'value',
    '#value' => $prematch['primary_field'] == '' || isset($form_state['values']['new_prematch']) && $form_state['values']['new_prematch'],
  );

  // Add a description of the prematch to the form array.
  $form['prematch_desc'] = array(
    '#value' => '<p>' . t('Before creating a new object, attempt to match an existing one using the fields and rules below. (Click cancel to skip this step.)') . '</p>',
  );

  // Add the select lists for the mapped Drupal field(s) to use in prematching.
  $form['primary'] = array(
    '#type' => 'select',
    '#title' => t('Primary Field'),
    '#options' => sf_prematch_get_options($map, true),
    '#default_value' => $prematch['primary_field'],
    '#required' => true,
  );
  $options = sf_prematch_get_options($map);
  $form['secondary'] = array(
    '#type' => 'select',
    '#title' => t('Secondary Field'),
    '#options' => $options,
    '#default_value' => $prematch['secondary_field'],
    '#required' => false,
  );
  $form['tertiary'] = array(
    '#type' => 'select',
    '#title' => t('Tertiary Field'),
    '#options' => $options,
    '#default_value' => $prematch['tertiary_field'],
    '#required' => false,
  );

  // Create options to use in rule select.
  $options = array(
    SF_PREMATCH_PRIMARY_SECONDARY_AND_TERTIARY => 'primary, secondary and tertiary fields',
    SF_PREMATCH_PRIMARY_AND_SECONDARY => 'primary and secondary fields',
    SF_PREMATCH_PRIMARY => 'primary field',
  );

  // Add the select list for prematching rule.
  $form['rule'] = array(
    '#type' => 'select',
    '#title' => t('Only consider a match if the found object matches'),
    '#options' => $options,
    '#default_value' => $prematch['rule'],
    '#required' => true,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save changes'),
    '#suffix' => l(t('Cancel'), SALESFORCE_PATH_FIELDMAPS),
  );
  return $form;
}