function commerce_cart_field_formatter_settings_form in Commerce Core 7
Implements hook_field_formatter_settings_form().
File
- modules/
cart/ commerce_cart.module, line 2623 - Implements the shopping cart system and add to cart features.
Code
function commerce_cart_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = array_merge(field_info_formatter_settings($display['type']), $display['settings']);
$element = array();
if ($display['type'] == 'commerce_cart_add_to_cart_form') {
$button_text = !empty($settings['button_text']) ? filter_xss($settings['button_text'], array()) : t('Add to cart');
$element['button_text'] = array(
'#type' => 'textfield',
'#title' => t('Button text'),
'#default_value' => $button_text,
'#description' => t('Text to use for the Add to Cart button. Default: %default', array(
'%default' => 'Add to cart',
)),
);
$element['show_quantity'] = array(
'#type' => 'checkbox',
'#title' => t('Display a textfield quantity widget on the add to cart form.'),
'#default_value' => $settings['show_quantity'],
);
$element['default_quantity'] = array(
'#type' => 'textfield',
'#title' => t('Default quantity'),
'#default_value' => $settings['default_quantity'] <= 0 ? 1 : $settings['default_quantity'],
'#element_validate' => array(
'commerce_cart_field_formatter_settings_form_quantity_validate',
),
'#size' => 16,
);
$element['combine'] = array(
'#type' => 'checkbox',
'#title' => t('Attempt to combine like products on the same line item in the cart.'),
'#description' => t('The line item type, referenced product, and data from fields exposed on the Add to Cart form must all match to combine.'),
'#default_value' => $settings['combine'],
);
$element['show_single_product_attributes'] = array(
'#type' => 'checkbox',
'#title' => t('Show attribute widgets even if the Add to Cart form only represents one product.'),
'#description' => t('If enabled, attribute widgets will be shown on the form with the only available options selected.'),
'#default_value' => $settings['show_single_product_attributes'],
);
// Add a conditionally visible line item type element.
$types = commerce_product_line_item_types();
if (count($types) > 1) {
$element['line_item_type'] = array(
'#type' => 'select',
'#title' => t('Add to Cart line item type'),
'#options' => array_intersect_key(commerce_line_item_type_get_name(), drupal_map_assoc($types)),
'#default_value' => $settings['line_item_type'],
);
}
else {
$element['line_item_type'] = array(
'#type' => 'hidden',
'#value' => reset($types),
);
}
}
return $element;
}