You are here

function _bpc_display_get_reference_field in Commerce Bulk Product Creation 7.2

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

string $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 _bpc_display_get_reference_field()
bpc_display_create_node in modules/bpc_display/bpc_display.module
Create a display node that links to a set of products.
bpc_display_form_node_form_alter in modules/bpc_display/bpc_display.module
Implements hook_form_BASE_FORM_ID_alter().
bpc_display_get_node_types in modules/bpc_display/bpc_display.module
Determine the node types that can serve as display nodes.

File

modules/bpc_display/bpc_display.module, line 284
Allows automatic display node creation for Commerce bulk product creation.

Code

function _bpc_display_get_reference_field($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;
      }
    }
  }
}