function commerce_webform_line_item_configuration in Commerce Webform 8
Same name and namespace in other branches
- 7.2 commerce_webform.module \commerce_webform_line_item_configuration()
- 7 commerce_webform.module \commerce_webform_line_item_configuration()
Ensures the commerce webform line item type contains a product reference field, webform nid reference field and webform submission sid field.
Parameters
commerce_line_item $line_item_type: The info array of the line item type being configured.
File
- ./
commerce_webform.module, line 50 - Commerce Webform module file
Code
function commerce_webform_line_item_configuration($line_item_type) {
// Add the standard commerce product line item fields.
commerce_product_line_item_configuration($line_item_type);
// Add the webform line item fields.
$field_names['nid'] = 'commerce_webform_nid';
$field_names['sid'] = 'commerce_webform_sid';
foreach ($field_names as $type => $field_name) {
// Check the commerce webform fields are not there already.
$field = field_info_field($field_name);
$instance = field_info_instance('commerce_line_item', $field_name, 'commerce_webform');
if (empty($field)) {
$field = array(
'active' => '1',
'cardinality' => '1',
'deleted' => '0',
'entity_types' => array(
'commerce_line_item',
),
'field_name' => $field_name,
'foreign keys' => array(),
'indexes' => array(),
'module' => 'number',
'settings' => array(),
'translatable' => '0',
'type' => 'number_integer',
'locked' => TRUE,
);
$field = field_create_field($field);
}
if (empty($instance)) {
$instance = array(
'field_name' => $field_name,
'entity_type' => 'commerce_line_item',
'bundle' => 'commerce_webform',
'commerce_cart_settings' => array(
'field_access' => 0,
),
'default_value' => 0,
'deleted' => '0',
'label' => t('Webform ' . $type),
'required' => 0,
'settings' => array(
'max' => '',
'min' => '',
'prefix' => '',
'suffix' => '',
'user_register_form' => FALSE,
),
'description' => 'If this line item is connected to a commere_webform then this field will have a positive numeric value connecting it to the webform ' . $type,
'widget' => array(
'active' => 0,
'module' => 'number',
'settings' => array(),
'type' => 'number',
'weight' => '3',
),
'display' => array(),
);
$entity_info = entity_get_info('commerce_line_item');
// Spoof the default view mode and node teaser so its display type is set.
$entity_info['view modes'] += array(
'default' => array(),
'node_teaser' => array(),
);
foreach ($entity_info['view modes'] as $view_mode => $data) {
$instance['display'][$view_mode] = array(
'label' => 'hidden',
'module' => 'number',
'type' => 'number_integer',
'settings' => array(
'decimal_separator' => '.',
'prefix_suffix' => TRUE,
'scale' => 0,
'thousand_separator' => ' ',
),
'weight' => 5,
);
}
field_create_instance($instance);
}
}
}