function commerce_product_line_item_configuration in Commerce Core 7
Ensures the product line item type contains a product reference field.
This function is called by the line item module when it is enabled or this module is enabled. It invokes this function using the configuration_callback as specified above. Other modules defining product line item types should use this function to ensure their types have the required fields.
Parameters
$line_item_type: The info array of the line item type being configured.
File
- modules/
product_reference/ commerce_product_reference.module, line 1260 - Defines a field type for referencing products from other entities.
Code
function commerce_product_line_item_configuration($line_item_type) {
$type = $line_item_type['type'];
// Create the product reference field for the line item type.
commerce_product_reference_create_instance('commerce_product', 'commerce_line_item', $type, t('Product'));
// Look for or add a display path textfield to the product line item type.
$field_name = 'commerce_display_path';
commerce_activate_field($field_name);
field_cache_clear();
$field = field_info_field($field_name);
$instance = field_info_instance('commerce_line_item', $field_name, $type);
if (empty($field)) {
$field = array(
'field_name' => $field_name,
'type' => 'text',
'cardinality' => 1,
'entity_types' => array(
'commerce_line_item',
),
'translatable' => FALSE,
'locked' => TRUE,
);
$field = field_create_field($field);
}
if (empty($instance)) {
$instance = array(
'field_name' => $field_name,
'entity_type' => 'commerce_line_item',
'bundle' => $type,
'label' => t('Display path'),
'required' => TRUE,
'settings' => array(),
'widget' => array(
'type' => 'text_textfield',
'weight' => 0,
),
'display' => array(
'display' => array(
'label' => 'hidden',
'weight' => 0,
),
),
);
field_create_instance($instance);
}
}