You are here

function _salesforce_mapping_get_salesforce_object_type_options in Salesforce Suite 7.3

Helper to retreive a list of object type options.

Parameters

array $form_state: Current state of the form to store and retreive results from to minimize the need for recalculation.

bool $include_select: Choice to choose a select option or not. If TRUE, the first item will be "-- Select --". If FALSE, the first item will be the first item of the retreived objects. Defaults to TRUE.

Return value

array An array of values keyed by machine name of the object with the label as the value, formatted to be appropriate as a value for #options.

2 calls to _salesforce_mapping_get_salesforce_object_type_options()
salesforce_mapping_form in modules/salesforce_mapping/includes/salesforce_mapping.admin.inc
Return a form for a Salesforce mapping entity.
salesforce_pull_form_salesforce_settings_form_alter in modules/salesforce_pull/salesforce_pull.module
Implements hook_form_FORM_ID_alter().

File

modules/salesforce_mapping/includes/salesforce_mapping.admin.inc, line 996
Configuration page for creating and modifying a mapping.

Code

function _salesforce_mapping_get_salesforce_object_type_options(&$form_state, $include_select = TRUE) {
  if (isset($form_state['sfm_storage']['salesforce_object_type'])) {
    $sfobjects = $form_state['sfm_storage']['salesforce_object_type'];
  }
  else {
    $sfapi = salesforce_get_api();

    // Note that we're filtering SF object types to a reasonable subset.
    $sf_object_filter = array();
    if (variable_get('salesforce_limit_to_updateable', TRUE)) {
      $sf_object_filter['updateable'] = TRUE;
    }
    if (variable_get('salesforce_limit_to_triggerable', TRUE)) {
      $sf_object_filter['triggerable'] = TRUE;
    }
    $sfobjects = $sfapi
      ->objects($sf_object_filter);
    $form_state['sfm_storage']['salesforce_object_type'] = $sfobjects;
  }
  $sfobject_options = array();
  if ($include_select) {
    $sfobject_options[''] = '- ' . t('Select object type') . ' -';
  }
  foreach ($sfobjects as $object) {
    $sfobject_options[$object['name']] = $object['label'];
  }
  natsort($sfobject_options);
  return $sfobject_options;
}