You are here

function party_entity_update in Party 7

Same name and namespace in other branches
  1. 8.2 party.module \party_entity_update()

Implements hook_entity_update($entity, $type);

Trigger rules and update party label if an attached entity has been saved.

File

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

Code

function party_entity_update($entity, $type) {
  if ($type == "party" && module_exists('rules')) {
    rules_invoke_event('party_update', $entity);
  }

  // Get necessary entity info.
  $wrapper = entity_metadata_wrapper($type, $entity);

  // Get data sets.
  $data_sets = party_get_data_set_info();

  // Is this entity party of a data set?
  $data_set_name = FALSE;
  foreach ($data_sets as $name => $def) {
    if ($def['entity type'] == $type && $def['entity bundle'] == $wrapper
      ->getBundle()) {
      $data_set_name = $name;
      break;
    }
  }

  // If it's not part of a data set do nothing else
  if (!$data_set_name) {
    return;
  }

  // Update the primary fields if this is attached to a party.
  if (!empty($entity->party_attaching_party)) {
    $controller = entity_get_controller('party');
    $party = party_load($entity->party_attaching_party);
    $controller
      ->setPrimaryFields($party);
  }
}