Internet Commons

Your website development partner

Controls: show

Document

Comments:

[log in] or [register] to leave a comment for this document.


Go to: all documents

Options: show

Looking inside:
Drupal cookbook and ingredient guidelines
( display item 1)

Contact:

mail@internetcommons.ca

Website:

[home] [about] [help]

Subsites:
Members:

[profiles]

return
next
Document

commerce_customer_profile_reference

22-Apr-2013 [219]

• This field shows a drop down in the format of profile_id:User userid

  • dropdown is assembled based on hook_options_list, but that is only fired to one module - the owner.
  • possible to look into hook_field_widget series instead

Trace

Source of the drop down name format:

/**
 * Implements hook_options_list().
 */
function commerce_customer_options_list($field) {
  $options = array();

  // Loop through all customer matches.
  foreach (commerce_customer_match_customer_profiles($field) 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;
}

Trace:

commerce_customer.module around line 759, sets commerce_customer_profile_property_info_callback

/**
 * Implements hook_field_info().
 */
function commerce_customer_field_info() {
  return array(
    'commerce_customer_profile_reference' => array(
      'label' => t('Customer profile reference'),
      'description' => t('This field stores the ID of a related customer profile as an integer value.'),
      'settings' => array('profile_type' => 'billing'),
      'instance_settings' => array(),
      'default_widget' => 'options_select',
      'default_formatter' => 'commerce_customer_profile_reference_display',
      'property_type' => 'commerce_customer_profile',
      'property_callbacks' => array('commerce_customer_profile_property_info_callback'),
    ),
  );
}

which runs from commerce_customer.module line 949.

/**
 * Callback to alter the property info of the reference field.
 *
 * @see commerce_customer_field_info().
 */
function commerce_customer_profile_property_info_callback(&$info, $entity_type, $field, $instance, $field_type) {
  $property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']];
  $property['options list'] = 'entity_metadata_field_options_list';
}

which sets 'options list':

$property['options list'] = 'entity_metadata_field_options_list';

which is a system callback in contributions/entity/modules/callbacks.inc'

function entity_metadata_field_options_list($name, $info) {
  $field_property_info = $info;
  if (is_numeric($name) && isset($info['parent'])) {
    // The options list is to be returned for a single item of a multiple field.
    $field_property_info = $info['parent']->info();
    $name = $field_property_info['name'];
  }
  if (($field = field_info_field($name)) && isset($field_property_info['parent'])) {
    // Retrieve the wrapped entity holding the field.
    $wrapper = $field_property_info['parent'];
    try {
      $entity = $wrapper->value();
    }
    catch (EntityMetadataWrapperException $e) {
      // No data available.
      $entity = NULL;
    }
    $instance = $wrapper->getBundle() ? field_info_instance($wrapper->type(), $name, $wrapper->getBundle()) : NULL;
    return (array) module_invoke($field['module'], 'options_list', $field, $instance, $wrapper->type(), $entity);
  }
}

which calls hook_options_list, but only to the field's single module.


Survey

'commerce_customer_profile_reference' as a string is found in:

  • commerce_cart.module (modules\cart\)
  • commerce_customer.install (modules\customer\)
  • commerce_customer.module (modules\customer\)
  • commecre_customer.checkout_pane.inc (modules\customer\includes\)
  • commerce_order.module (modules\order\)
  • commerce_order.rules.inc (modules\order\)
  • commerce_order.forms.inc (modules\order\includes\)

in commecre_customer.checkout_pane.inc see line 22 in commerce_customer_profile_pane_settings_form, identified as 'Checkout pane callback: returns the customer profile pane's settings form'.

11 references in commerce_customer.module.

see in particular:

line 756:

/**
 * Implements hook_field_info().
 */
function commerce_customer_field_info() {

line 871:

/**
 * Implements hook_field_formatter_view().
 */
function commerce_customer_field_formatter_view(
   $entity_type, $entity, $field, $instance, $langcode, $items, $display) {

see line 1165 ff:

/**
 * Callback to alter the property info of the reference field.
 *
 * @see commerce_customer_field_info().
 */
function commerce_customer_profile_property_info_callback(
    &$info, $entity_type, $field, $instance, $field_type) {

and

/**
 * Fetches an array of all customer profiles matching the given parameters.
 *
 * This info is used in various places (allowed values, autocomplete results,
 * input validation...). Some of them only need the profile_ids, others
 * profile_id + titles, others yet profile_id + titles + rendered row (for
 * display in widgets).
 *
 * The array we return contains all the potentially needed information,
 * and lets calling functions use the parts they actually need.
 *
 * @param $field
 *   The field description.
 * @param $ids
 *   Optional product ids to lookup.
 * @param $limit
 *   If non-zero, limit the size of the result set.
 *
 * @return
 *   An array of valid profiles in the form:
 *   array(
 *     profile_id => array(
 *       'uid' => The user ID,
 *       'rendered' => The text to display in widgets (can be HTML)
 *     ),
 *     ...
 *   )
 */
function commerce_customer_match_customer_profiles($field, $ids = array(), $limit = 50) {
  $results = &drupal_static(__FUNCTION__, array());

  // Create unique id for static cache.
  $cid = implode(':', array(
    $field['field_name'],
    implode('-', $ids),
    $limit,
  ));

  if (!isset($results[$cid])) {
    $matches = _commerce_customer_match_customer_profiles_standard($field, $ids, $limit);

    // Store the results.
    $results[$cid] = !empty($matches) ? $matches : array();
  }

  return $results[$cid];
}
next display
(showing first display)