You are here

function salesforce_api_fieldmap_remove_field in Salesforce Suite 7.2

Same name and namespace in other branches
  1. 6.2 salesforce_api/salesforce_api.admin.inc \salesforce_api_fieldmap_remove_field()

Given a fieldmap name and a field, remove the field from the fieldmap. Redirect to the fieldmap edit page unless specified.

Parameters

object $map - the name of the fieldmap, or the fieldmap itself:

string $field - the name of the field to be removed:

bool $redirect (optional) - default true. Whether to redirect to the fieldmap edit form.:

1 string reference to 'salesforce_api_fieldmap_remove_field'
salesforce_api_menu in salesforce_api/salesforce_api.module
Implements hook_menu().

File

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

Code

function salesforce_api_fieldmap_remove_field($map, $field, $redirect = TRUE) {
  $object_definition = salesforce_api_fieldmap_objects_load('salesforce', 'salesforce', $map->salesforce);
  $success = TRUE;
  if (empty($object_definition['fields'][$field])) {
    $success = FALSE;
  }
  elseif ($object_definition['fields'][$field]['type'] & SALESFORCE_FIELD_CREATEABLE && !($object_definition['fields'][$field]['type'] & SALESFORCE_FIELD_NILLABLE | SALESFORCE_FIELD_DEFAULTEDONCREATE)) {

    // Don't allow removing required fields.
    $success = FALSE;
  }
  else {
    unset($map->fields[$field]);
    salesforce_api_fieldmap_save($map);
    $success = TRUE;
  }
  if ($redirect) {
    drupal_goto(SALESFORCE_PATH_FIELDMAPS . '/' . $map->name . '/edit');
    exit;
  }
  return $success;
}