You are here

function crm_core_contact_get_primary_field_value in CRM Core 7

Get CRM Core Contact primary field value.

Parameters

CRMCoreContactEntity $contact: CRM Core Contact.

string $primary_field: Primary field name.

Return value

string Value of specified primary field or empty string.

3 calls to crm_core_contact_get_primary_field_value()
crm_core_contact_get_primary_address_field_value in modules/crm_core_contact/crm_core_contact.module
Returns primary address.
crm_core_contact_get_primary_email_field_value in modules/crm_core_contact/crm_core_contact.module
Returns primary email.
crm_core_contact_get_primary_phone_field_value in modules/crm_core_contact/crm_core_contact.module
Returns primary phone.

File

modules/crm_core_contact/crm_core_contact.module, line 177
Provides default CRM Core Contact entities and the ability to create more.

Code

function crm_core_contact_get_primary_field_value(CRMCoreContactEntity $contact, $primary_field) {
  $field = crm_core_contact_get_primary_field_name($contact, $primary_field);
  $field_value = '';
  if (empty($field)) {

    // TODO: use watchdog instead.
    // Check that user has access to configure crm_core_contact.
    if (user_access('administer contact types')) {

      // Alert privileged users that requested primary field didn't configured.
      $path = 'admin/structure/crm-core/contact-types/manage/' . $contact->type;
      $message = "Some module requested value of primary field %field of" . " contact of %contact_type type, but this primary field is not" . " configured for this contact type. You can configure it !here.";
      drupal_set_message(t($message, array(
        '%contact_type' => $contact->type,
        '%field' => $primary_field,
        '!here' => l(t('here'), $path),
      )), 'warning');
    }
  }
  else {
    $contact_wrapper = entity_metadata_wrapper('crm_core_contact', $contact);
    $field_value = $contact_wrapper->{$field}
      ->value();
  }
  return $field_value;
}