You are here

function salesforce_mapping_entity_delete in Salesforce Suite 7.3

Same name and namespace in other branches
  1. 8.4 modules/salesforce_mapping/salesforce_mapping.module \salesforce_mapping_entity_delete()
  2. 8.3 modules/salesforce_mapping/salesforce_mapping.module \salesforce_mapping_entity_delete()
  3. 5.0.x modules/salesforce_mapping/salesforce_mapping.module \salesforce_mapping_entity_delete()

Implements hook_entity_delete().

File

modules/salesforce_mapping/salesforce_mapping.module, line 592

Code

function salesforce_mapping_entity_delete($entity, $type) {

  // Delete any Salesforce object mappings with this entity.
  list($entity_id, , $bundle) = entity_extract_ids($type, $entity);
  $mapping_object = salesforce_mapping_object_load_by_drupal($type, $entity_id);

  // No mapping object for this entity, return.
  if (!$mapping_object) {
    return;
  }

  // Only delete the mapping object if it won't be handled by the delete
  // trigger in the mapping. We're avoiding the issue of deleting a mapping
  // object before deleting the mapped object.
  $mappings = salesforce_mapping_load_multiple(array(
    'drupal_entity_type' => $type,
    'drupal_bundle' => $bundle,
  ));
  foreach ($mappings as $mapping) {

    // Look for any mapping with the delete trigger enabled.
    if ($mapping->sync_triggers & SALESFORCE_MAPPING_SYNC_DRUPAL_DELETE) {
      return;
    }
  }

  // No mappings have the delete hook enabled, go ahead and delete the mapping
  // object.
  $mapping_object
    ->delete();
}