You are here

function commerce_customer_options_list in Commerce Core 7

Implements hook_options_list().

File

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

Code

function commerce_customer_options_list($field) {
  $options = array();

  // Look for an options list limit in the field settings.
  if (!empty($field['settings']['options_list_limit'])) {
    $limit = (int) $field['settings']['options_list_limit'];
  }
  else {
    $limit = NULL;
  }

  // Loop through all customer matches.
  foreach (commerce_customer_match_customer_profiles($field, array(), $limit) as $profile_id => $data) {

    // Add them to the options list in optgroups by customer profile type.
    $name = check_plain(commerce_customer_profile_type_get_name($data['type']));
    $options[$name][$profile_id] = t('@profile: User @user', array(
      '@profile' => $profile_id,
      '@user' => $data['uid'],
    ));
  }

  // Simplify the options list if only one optgroup exists.
  if (count($options) == 1) {
    $options = reset($options);
  }
  return $options;
}