function _crm_core_user_sync_get_related_entity in CRM Core 7
Same name and namespace in other branches
- 8.2 modules/crm_core_user_sync/crm_core_user_sync.module \_crm_core_user_sync_get_related_entity()
Copied from relation.module, (beta 1) gives an error if the entity id is not found, so need to fix that
4 calls to _crm_core_user_sync_get_related_entity()
- crm_core_user_sync_contact_get_user_properties in modules/
crm_core_user_sync/ crm_core_user_sync.module - crm_core_user_sync_get_related_entity in modules/
crm_core_user_sync/ crm_core_user_sync.module - Retrieves the related entity based on entity type, ids and relation type.
- crm_core_user_sync_user_update in modules/
crm_core_user_sync/ crm_core_user_sync.module - Implements hook_user_update()
- views_plugin_argument_default_contact_id::get_argument in modules/
crm_core_user_sync/ views/ views_plugin_argument_default_contact_id.inc - Return the default argument.
File
- modules/
crm_core_user_sync/ crm_core_user_sync.module, line 383
Code
function _crm_core_user_sync_get_related_entity($entity_type, $entity_id, $relation_type = NULL, $r_index = NULL, $check_access = TRUE) {
$query = relation_query($entity_type, $entity_id);
// Allows to skip node access checks.
if (!$check_access) {
$query
->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');
}
if ($relation_type) {
$query
->propertyCondition('relation_type', $relation_type);
}
if (isset($r_index)) {
$query
->fieldCondition('endpoints', 'r_index', $r_index);
}
$results = $query
->execute();
if (empty($results)) {
return;
}
$result = reset($results);
$relation = relation_load($result->rid);
$request_key = $entity_type . ':' . $entity_id;
$entities = $relation->endpoints[LANGUAGE_NONE];
if (isset($entities[0]['entity_type']) && isset($entities[0]['entity_id'])) {
$first_entity_key = $entities[0]['entity_type'] . ':' . $entities[0]['entity_id'];
if (isset($r_index)) {
$request_key = $request_key . ':' . $r_index;
$first_entity_key = $first_entity_key . ':' . $entities[0]['r_index'];
}
if ($request_key == $first_entity_key) {
$other_endpoints = entity_load($entities[1]['entity_type'], array(
$entities[1]['entity_id'],
));
return reset($other_endpoints);
}
$other_endpoints = entity_load($entities[0]['entity_type'], array(
$entities[0]['entity_id'],
));
return reset($other_endpoints);
}
}