You are here

function party_entity_delete in Party 7

Implements hook_entity_delete.

File

./party.module, line 1355
Provides a generic CRM party entity.

Code

function party_entity_delete($entity, $entity_type) {
  $query = db_select('party_attached_entity', 'pae')
    ->fields('pae', array(
    'pid',
    'data_set',
    'delta',
  ))
    ->condition('entity_type', $entity_type)
    ->condition('eid', entity_id($entity_type, $entity));
  $query
    ->addExpression('CONCAT(pid,\'-\',delta)', 'id');
  $rows = $query
    ->execute()
    ->fetchAllAssoc('id');
  foreach ($rows as $row) {
    $party = party_load($row->pid);
    if ($party) {
      $party
        ->getDataSetController($row->data_set)
        ->detachEntityByDelta($row->delta)
        ->save();
    }
  }
}