function salesforce_api_fieldmap_field_delete in Salesforce Suite 7.2
Same name and namespace in other branches
- 6.2 salesforce_api/salesforce_api.module \salesforce_api_fieldmap_field_delete()
- 7 salesforce_api/salesforce_api.module \salesforce_api_fieldmap_field_delete()
Remove a field from all fieldmaps. This is particularly useful for implementations of hook_field_delete_instance. May be use to delete an occurrence in a single fieldmap (by supplying drupal_entity, drupal_bundle and/or salesforce_type), or every occurence in all fieldmaps (by supplying only the fieldname).
@todo Ensure that this behaves correctly, especially for if it is a Salesforce field being deleted.
Parameters
string $fieldname: The name of the field to be deleted. Either a Field API field, or a Salesforce field
array $conditions (optional): If given, limit deleting of the field to this Drupal entity, Drupal bundle, and/or Salesforce type. These are the fields in the {salesforce_fieldmap} table: drupal_entity, drupal_bundle, salesforce
See also
sf_entity/sf_entity.module:sf_entity_field_delete_instance
1 call to salesforce_api_fieldmap_field_delete()
- sf_entity_field_delete_instance in sf_entity/
sf_entity.module - Implements hook_field_delete_instance(). Delete a field from a Salesforce fieldmap when the field instance is deleted.
File
- salesforce_api/
salesforce_api.module, line 741 - Defines an API that enables modules to interact with the Salesforce server.
Code
function salesforce_api_fieldmap_field_delete($fieldname, $conditions = array()) {
// If entity, bundle, and/or salesforce type are specified, load just the fieldmaps for that combination of conditions.
if (isset($conditions['drupal_entity']) && isset($conditions['drupal_bundle']) && isset($conditions['salesforce']) || isset($conditions['drupal_entity']) || isset($conditions['salesforce'])) {
$maps = salesforce_api_salesforce_fieldmap_load_by($conditions);
}
else {
$maps = salesforce_api_salesforce_fieldmap_load_all();
}
foreach ($maps as $map) {
// In the extremely unlikely event that a Salesforce field and a Drupal
// field share the same name, this function handles both.
if (isset($conditions['drupal_entity']) && !empty($conditions['drupal_entity'])) {
$drupal_fieldname = array_search($fieldname, $map->fields);
if ($drupal_fieldname) {
unset($map->fields[$drupal_fieldname]);
if (user_access('administer salesforce')) {
drupal_set_message(t('Removed Drupal field from salesforce_api !link', array(
'!link' => l('fieldmap ' . $fieldmap_id, SALESFORCE_PATH_OBJECT . '/' . $fieldmap_id),
)));
}
salesforce_api_fieldmap_save($map);
}
}
if (isset($conditions['salesforce'])) {
$sf_fieldname = array_search($fieldname, $map->fields);
if (!empty($map->fields[$sf_fieldname])) {
unset($map->fields[$sf_fieldname]);
if (user_access('administer salesforce')) {
drupal_set_message(t('Removed Salesforce field from salesforce_api !link', array(
'@link' => l('fieldmap ' . $fieldmap_id, SALESFORCE_PATH_OBJECT . '/' . $fieldmap_id),
)));
}
salesforce_api_fieldmap_save($map);
}
}
}
}