You are here

function party_log_entity_merge in Party 7

Implements hook_entity_merge().

File

modules/party_log/party_log.module, line 243
Provide a framework for logging things that happen to and with parties.

Code

function party_log_entity_merge($target_entity, $entity_1, $entity_2, $entity_type) {
  global $user;
  if ($entity_type != 'party') {
    return;
  }

  // Build message
  $values = array(
    'arguments' => array(
      '@other_party_label' => entity_label($entity_type, $target_entity),
    ),
    'timestamp' => time(),
  );
  $message = message_create('party_merged_into', $values, $user);
  $wrapper = entity_metadata_wrapper('message', $message);
  $wrapper->party = $entity_2;
  $wrapper->other_party = $target_entity;
  $wrapper
    ->save();

  // Build message
  $values = array(
    'arguments' => array(
      '@other_party_label' => entity_label($entity_type, $entity_2),
    ),
    'timestamp' => time(),
  );
  $message = message_create('party_had_other_merged_in', $values, $user);
  $wrapper = entity_metadata_wrapper('message', $message);
  $wrapper->party = $target_entity;
  $wrapper->other_party = $entity_2;
  $wrapper
    ->save();
}