You are here

function _commerce_bpc_get_reference_field_name in Commerce Bulk Product Creation 7

Determine the name of the product reference field (if any) on a node type.

This is used, for example, to determine which field to prepopulate in the node form after bulk creation.

@todo Right now, we simply return the first product reference field we find. What is the best way to deal with multiple product reference fields?

Parameters

object $node_type: The bundle name of the node type for which the product reference field is to be determined.

Return value

string|NULL The machine name of the product reference field, if there is one, NULL otherwise.

3 calls to _commerce_bpc_get_reference_field_name()
commerce_bpc_create_display_node in ./commerce_bpc.forms.inc
Create a display node that links to a set of products.
commerce_bpc_form_node_form_alter in ./commerce_bpc.module
Implements hook_form_BASE_FORM_ID_alter().
commerce_bpc_get_node_types in ./commerce_bpc.module
Determine node types that can serve as display nodes.

File

./commerce_bpc.module, line 604

Code

function _commerce_bpc_get_reference_field_name($node_type) {
  if ($fields = field_info_instances('node', $node_type)) {
    foreach ($fields as $name => $field) {
      $field_info = field_read_field($name);
      if ($field_info['type'] == 'commerce_product_reference') {
        return $name;
      }
    }
  }
}