You are here

function crm_core_contact_label in CRM Core 7

Entity label callback.

Parameters

object $contact: A fully loaded CRM Core Contact object.

Return value

string Raw formatted string. This should be run through check_plain().

2 calls to crm_core_contact_label()
CRMCoreContactController::save in modules/crm_core_contact/includes/crm_core_contact.controller.inc
Updates 'changed' property on save.
CRMCoreContactEntity::defaultLabel in modules/crm_core_contact/includes/crm_core_contact.controller.inc
Defines the entity label if the 'entity_class_label' callback is used.

File

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

Code

function crm_core_contact_label($contact) {
  $cache =& drupal_static(__FUNCTION__, array());
  if (!isset($cache[$contact->contact_id])) {

    // Check whether bundle type label function exists.
    // This is needed if we want to have different labels per contact type.
    // For example Individual contact's label is person's Name.
    // But for Organization -- organization's name.
    $function = 'crm_core_contact_' . $contact->type . '_label';
    if (function_exists($function)) {
      return $function($contact);
    }
    $contact_wrapper = entity_metadata_wrapper('crm_core_contact', $contact);
    $field_info = field_info_field('contact_name');
    $item = $field_info['cardinality'] == '1' ? $contact_wrapper->contact_name
      ->value() : $contact_wrapper->contact_name[0]
      ->value();

    // Load the label format.
    $format = name_get_format_by_machine_name('crm_core_contact_label_format');
    if (empty($format)) {
      $format = name_get_format_by_machine_name('default');
    }
    $settings = array(
      'markup' => FALSE,
      'object' => $contact,
      'type' => 'crm_core_contact',
    );

    // There is no need to store in cache data for not saved contacts.
    if (empty($contact->contact_id)) {
      return name_format($item, $format, $settings);
    }
    $cache[$contact->contact_id] = name_format($item, $format, $settings);
  }
  return $cache[$contact->contact_id];
}