You are here

function salesforce_api_settings_form in Salesforce Suite 7.2

Same name and namespace in other branches
  1. 5.2 salesforce_api/salesforce_api.module \salesforce_api_settings_form()
  2. 6.2 salesforce_api/salesforce_api.admin.inc \salesforce_api_settings_form()
  3. 7 salesforce_api/salesforce_api.admin.inc \salesforce_api_settings_form()

The settings form at admin/settings/salesforce.

2 string references to 'salesforce_api_settings_form'
salesforce_api_menu in salesforce_api/salesforce_api.module
Implements hook_menu().
sf_prematch_form_alter in sf_prematch/sf_prematch.module
Implements hook_form_alter().

File

salesforce_api/salesforce_api.admin.inc, line 12
Contains the admin page callbacks for the Salesforce module, including forms for general settings and fieldmap administration.

Code

function salesforce_api_settings_form($form, &$form_state) {
  $form = array();

  // Let user know if read-only is set
  if (variable_get('salesforce_api_read_only', FALSE)) {
    drupal_set_message(t('Read-only mode is enabled. No data will be exported to Salesforce'), 'warning');
  }

  // Use the username field to collapse the API settings fieldset.
  $username = variable_get('salesforce_api_username', '');
  $form['api'] = array(
    '#type' => 'fieldset',
    '#title' => t('Salesforce API settings'),
    '#description' => t('Use your Salesforce.com login information for these username and password fields.'),
    '#collapsible' => !empty($username),
    '#collapsed' => !empty($username),
    '#weight' => -10,
  );
  $form['api']['salesforce_api_username'] = array(
    '#type' => 'password',
    '#title' => t('Username'),
    '#description' => t('Should be in the form of an e-mail address.'),
    '#default_value' => !empty($form_state['values']['salesforce_api_username']) ? $form_state['values']['salesforce_api_username'] : '',
    '#required' => !variable_get('salesforce_api_username', FALSE),
  );
  $form['api']['salesforce_api_password'] = array(
    '#type' => 'password',
    '#title' => t('Password'),
    '#description' => t('Enter the password used when logging into Salesforce.'),
    '#default_value' => !empty($form_state['values']['salesforce_api_password']) ? $form_state['values']['salesforce_api_password'] : '',
    '#required' => !variable_get('salesforce_api_password', FALSE),
  );
  $form['api']['salesforce_api_token'] = array(
    '#type' => 'password',
    '#title' => t('Security token'),
    '#description' => t('Set your security token by logging into Salesforce and
      navigating to Setup > My Personal Information > Reset My Security Token.'),
    '#default_value' => !empty($form_state['values']['salesforce_api_token']) ? $form_state['values']['salesforce_api_token'] : '',
    '#required' => !variable_get('salesforce_api_token', FALSE),
  );
  if (!empty($username)) {
    $form['api']['#description'] = t('Salesforce.com connection is working properly.<br />Edit the following
        fields only if you wish to change your login credentials.');
    $form['api']['salesforce_api_reset_credentials'] = array(
      '#type' => 'checkbox',
      '#title' => 'Clear Salesforce API credentials',
      '#description' => 'Erase current API login settings. Clearing Salesforce
        API credentials will prevent your website from connecting to Salesforce.com',
    );
  }
  if (salesforce_api_encryption_available(array(
    'display_all' => TRUE,
  ))) {
    $form['api']['encryption'] = array(
      '#type' => 'fieldset',
      '#title' => 'Encryption',
    );
    $form['api']['encryption']['status'] = array(
      '#markup' => 'Encryption is available and configured properly.',
      '#prefix' => '<div class = "messages status">',
      '#suffix' => '</div>',
    );
    $form['api']['encryption']['salesforce_api_encrypt'] = array(
      '#type' => 'checkbox',
      '#title' => 'Encrypt Salesforce credentials',
      '#description' => 'Note: enabling this setting will not encrypt existing credentials.',
      '#default_value' => TRUE,
    );
  }
  $form['log'] = array(
    '#type' => 'fieldset',
    '#title' => t('Log settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => -9,
  );
  $form['log']['salesforce_api_activity_log'] = array(
    '#type' => 'radios',
    '#title' => t('Activity log level'),
    '#options' => array(
      SALESFORCE_LOG_NONE => t('Do not log any Salesforce activities.'),
      SALESFORCE_LOG_SOME => t('Log important Salesforce activities.'),
      SALESFORCE_LOG_ALL => t('Log all Salesforce activitiies.'),
    ),
    '#default_value' => variable_get('salesforce_api_activity_log', SALESFORCE_LOG_SOME),
  );
  $form['log']['salesforce_api_error_log'] = array(
    '#type' => 'radios',
    '#title' => t('Error log level'),
    '#options' => array(
      SALESFORCE_LOG_NONE => t('Do not log any Salesforce errors.'),
      SALESFORCE_LOG_SOME => t('Log important Salesforce errors.'),
      SALESFORCE_LOG_ALL => t('Log all Salesforce errors.'),
    ),
    '#default_value' => variable_get('salesforce_api_error_log', SALESFORCE_LOG_ALL),
  );
  $form['log']['salesforce_api_debug'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display debug messages'),
    '#default_value' => variable_get('salesforce_api_debug', TRUE),
  );
  $form['objects'] = array(
    '#type' => 'fieldset',
    '#title' => t('Object settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => -9,
  );
  $form['objects']['salesforce_api_entity_deleted_policy'] = array(
    '#type' => 'select',
    '#title' => t('Entity Deleted Policy'),
    '#description' => t('When a Salesforce object is deleted, Drupal may encounter errors when trying to update any linked objects. This settings indicates how such errors should be handled. "Do Nothing" will cause Drupal to log such errors, but take no further action. "Unlink and Upsert" will cause Drupal to remove any existing link for the current object, and re-attempt the upsert.'),
    '#options' => array(
      SALESFORCE_DELETED_POLICY_UPSERT => t('Unlink and Upsert'),
      SALESFORCE_DELETED_POLICY_NOOP => t('Do Nothing'),
    ),
    '#default_value' => variable_get('salesforce_api_entity_deleted_policy', SALESFORCE_DELETED_POLICY_UPSERT),
  );
  $form['objects']['cache'] = array(
    '#type' => 'fieldset',
    '#title' => t('Caching'),
  );
  $form['objects']['cache']['clear_cache'] = array(
    '#type' => 'item',
    '#value' => t('Caching data improves performance, however your Drupal site will be unaware of any alterations made to your Salesforce installation unless the cached data is refreshed. Select the lifetime the object data after which the cache will be automatically refreshed.  To refresh all cached object data on your site, click the button below.'),
  );
  $period = drupal_map_assoc(array(
    32400,
    43200,
    86400,
    172800,
    259200,
    604800,
    1209600,
    2419200,
    4838400,
    9676800,
  ), 'format_interval');
  $period[CACHE_PERMANENT] = t('<none>');
  $form['objects']['cache']['salesforce_api_object_expire'] = array(
    '#type' => 'select',
    '#title' => t('Minimum cache lifetime'),
    '#options' => $period,
    '#default_value' => variable_get('salesforce_api_object_expire', CACHE_PERMANENT),
  );
  $form['objects']['cache']['clear_cache_clear'] = array(
    '#type' => 'submit',
    '#value' => t('Clear cached object data'),
    '#submit' => array(
      'salesforce_api_cache_build',
    ),
  );
  $form['proxy'] = array(
    '#type' => 'fieldset',
    '#title' => t('Proxy settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['proxy']['salesforce_api_proxy'] = array(
    '#type' => 'checkbox',
    '#title' => t('Connect to Salesforce via a proxy'),
    '#description' => 'Note: enabling this setting will cause all requests to Salesforce to go via the proxy defined below.',
    '#default_value' => variable_get('salesforce_api_proxy', FALSE),
  );
  $form['proxy']['salesforce_api_proxy_host'] = array(
    '#type' => 'textfield',
    '#title' => t('Proxy Hostname'),
    '#description' => t('The hostname the proxy is on.'),
    '#default_value' => variable_get('salesforce_api_proxy_host', ''),
  );
  $form['proxy']['salesforce_api_proxy_port'] = array(
    '#type' => 'textfield',
    '#title' => t('Proxy Port'),
    '#description' => t('The port the proxy is on.'),
    '#default_value' => variable_get('salesforce_api_proxy_port', ''),
  );
  $form['proxy']['salesforce_api_proxy_login'] = array(
    '#type' => 'password',
    '#title' => t('Proxy Username'),
    '#description' => t('The username for the proxy if applicable.'),
    '#default_value' => variable_get('salesforce_api_proxy_login', ''),
  );
  $form['proxy']['salesforce_api_proxy_password'] = array(
    '#type' => 'password',
    '#title' => t('Proxy Password'),
    '#description' => t('The password for the proxy if applicable.'),
    '#default_value' => variable_get('salesforce_api_proxy_password', ''),
  );

  // Validate handler makes sure that the salesforce_api_password doesn't get set to null on accident
  $form['#validate'][] = 'salesforce_api_settings_form_validate';
  $form['#submit'][] = 'salesforce_api_settings_form_submit';
  return system_settings_form($form);
}