You are here

function commerce_customer_profile_default_label in Commerce Core 7

Returns the default label for a customer profile.

Parameters

$profile: A fully loaded customer profile object.

Return value

The full name of the default address if available or the profile ID.

2 string references to 'commerce_customer_profile_default_label'
commerce_customer_profile_label in modules/customer/commerce_customer.module
Entity label callback: returns the label for an individual customer profile.
commerce_customer_profile_types in modules/customer/commerce_customer.module
Returns an array of customer profile type arrays keyed by type.

File

modules/customer/commerce_customer.module, line 115
Defines the customer profile entity and API functions to manage customers and interact with them.

Code

function commerce_customer_profile_default_label($profile) {
  $label = '';

  // If the profile has a default address field...
  if (!empty($profile->commerce_customer_address)) {

    // Wrap the customer profile object for easier access to its field data.
    $profile_wrapper = entity_metadata_wrapper('commerce_customer_profile', $profile);
    if (isset($profile_wrapper->commerce_customer_address->name_line)) {
      $label = $profile_wrapper->commerce_customer_address->name_line
        ->value();
    }
  }

  // Return the profile ID if we couldn't derive a label from an address field.
  if (empty($label)) {
    $label = $profile->profile_id;
  }
  return $label;
}