You are here

function civicrm_entity_action_load_user in CiviCRM Entity 7

Same name and namespace in other branches
  1. 7.2 civicrm_entity.module \civicrm_entity_action_load_user()

Given a contact object return the Drupal user.

Parameters

StdClass $entity: Contact Std Object

Return value

object Drupal user object.

2 calls to civicrm_entity_action_load_user()
civicrm_entity_action_load_create_user in ./civicrm_entity.module
Load or create user as appropriate.
civicrm_entity_user_exists in ./civicrm_entity.module
Condition Drupal User Account exists for contact.
1 string reference to 'civicrm_entity_action_load_user'
civicrm_entity_rules_action_info in ./civicrm_entity.rules.inc
Implements hook_rules_action_info().

File

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

Code

function civicrm_entity_action_load_user($entity) {
  $domain_id = civicrm_api('domain', 'getvalue', array(
    'version' => 3,
    'return' => 'id',
    'current_domain' => TRUE,
  ));
  $params = array(
    'version' => 3,
    'contact_id' => $entity->id,
    'return' => 'uf_id',
    'domain_id' => $domain_id,
  );
  $contact = civicrm_api('uf_match', 'getsingle', $params);
  if (empty($contact['is_error'])) {
    return array(
      'civicrm_user' => user_load($contact['uf_id']),
    );
  }
}