You are here

function sf_entity_salesforce_form_submit in Salesforce Suite 7

Same name and namespace in other branches
  1. 7.2 sf_entity/sf_entity.module \sf_entity_salesforce_form_submit()

File

sf_entity/sf_entity.module, line 641
Integrates fieldable entities with the Salesforce API.

Code

function sf_entity_salesforce_form_submit($form, &$form_state) {
  $values = $form_state['values'];
  $info = $values['entity info'];
  $keys = $values['entity keys'];
  $entities = entity_load($values['entity type'], $keys);
  $entity = current($entities);
  switch ($values['op']) {

    // Export the node to Salesforce.
    case t('Export'):
      $sfid = empty($form_state['values']['sfid']) ? NULL : $form_state['values']['sfid'];
      if (sf_entity_export($entity, $form_state['values']['fieldmap'], $sfid)) {
        drupal_set_message(t('%entity successfully exported to Salesforce.', array(
          '%entity' => $values['entity type'],
        )));
      }
      else {
        drupal_set_message(t('An error occurred while exporting the %entity to Salesforce.  Check the watchdog for more information.', array(
          '%entity' => $values['entity type'],
        )), 'error');
      }
      break;

    // Import changes from Salesforce.
    case t('Import'):
      if (sf_node_import($form_state['values']['sfid'], $form_state['values']['fieldmap'], $entity)) {
        drupal_set_message(t('The %entity has been updated with values from Salesforce.', array(
          '%entity' => $values['entity type'],
        )));
      }
      else {
        drupal_set_message(t('An error occurred while importing the changes from Salesforce. Check watchdog for more information.'), 'error');
      }
      break;
  }
}