You are here

function civicrm_entity_civicrm_post in CiviCRM Entity 7

Same name and namespace in other branches
  1. 8.3 civicrm_entity.module \civicrm_entity_civicrm_post()
  2. 7.2 civicrm_entity.module \civicrm_entity_civicrm_post()

Implement the post hook and fire the corresponding rules event.

Parameters

$op:

$object_name:

$object_id:

$object_ref:

File

./civicrm_entity.module, line 875
Implement CiviCRM entities as a Drupal Entity.

Code

function civicrm_entity_civicrm_post($op, $object_name, $object_id, &$object_ref) {
  if (!module_exists('rules')) {
    return;
  }
  $contact_types = array(
    'Individual',
    'Household',
    'Organization',
  );
  if (in_array($object_name, $contact_types)) {
    $object_name = 'Contact';
  }
  $valid_objects = _civicrm_entity_enabled_entities();
  $entity_name = _civicrm_entity_get_entity_name_from_camel($object_name);
  if (!in_array($entity_name, $valid_objects, TRUE)) {
    return;
  }
  $event_name = NULL;
  switch ($op) {
    case 'create':
    case 'edit':
    case 'delete':
      $event_name = 'civicrm_' . $entity_name . "_{$op}";
      break;
    default:
      break;
  }
  if ($entity_name == 'entity_tag') {

    // Argh entity tag is completely non-standard!!!
    // @see CRM-11933
    foreach ($object_ref[0] as $entity_tag) {
      $object = new CRM_Core_BAO_EntityTag();
      $object->entity_id = $entity_tag;
      $object->entity_table = 'civicrm_contact';
      $object->tag_id = $object_id;
      if ($object
        ->find(TRUE)) {

        // This find is probably not necessary but until more testing
        // on the tag create is done I will.
        rules_invoke_event($event_name, $object);
      }
    }
  }
  else {
    if ($event_name) {
      rules_invoke_event($event_name, $object_ref);
    }
  }
}