public static function Contact::loadByUser in RedHen CRM 8
Load a contact record from a user account.
Parameters
object $account: User object.
bool $status: Redhen status. Defaults to active.
Return value
mixed Contact or FALSE if not found.
3 calls to Contact::loadByUser()
- redhen_connection_entity_access in modules/
redhen_connection/ redhen_connection.module - Implements hook_entity_access().
- redhen_contact_form_user_form_alter in modules/
redhen_contact/ redhen_contact.module - Implements hook_form_FORM_ID_alter().
- redhen_contact_user_format_name_alter in modules/
redhen_contact/ redhen_contact.module - Implements hook_user_format_name_alter().
File
- modules/
redhen_contact/ src/ Entity/ Contact.php, line 256
Class
- Contact
- Defines the Contact entity.
Namespace
Drupal\redhen_contact\EntityCode
public static function loadByUser($account, $status = TRUE) {
$contact =& drupal_static(__FUNCTION__ . $account
->id(), FALSE);
// If we don't have a cached Contact and we have a uid to load the Contact
// by, proceed.
if (!$contact && !empty($account
->id())) {
// Find Contacts linked to the current Drupal User.
$query = \Drupal::entityQuery('redhen_contact');
$query
->condition('uid', $account
->id(), '=');
$query
->condition('status', $status);
$results = $query
->execute();
// If we find a Contact, load and return it.
if (!empty($results)) {
// There should always be only a single active user linked to an account.
$contact = Contact::load(reset($results));
}
}
return $contact;
}