function commerce_cart_handler_field_add_to_cart_form::options_form in Commerce Core 7
Provide the add to cart display options.
Overrides views_handler_field::options_form
File
- modules/
cart/ includes/ views/ handlers/ commerce_cart_handler_field_add_to_cart_form.inc, line 24
Class
- commerce_cart_handler_field_add_to_cart_form
- Field handler to present an add to cart form for the product..
Code
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['button_text'] = array(
'#type' => 'textfield',
'#title' => t('Button text'),
'#default_value' => $this->options['button_text'] ? filter_xss($this->options['button_text'], array()) : t('Add to cart'),
'#description' => t('Text to use in the Add to cart button. Default: %default', array(
'%default' => 'Add to cart',
)),
);
$form['show_quantity'] = array(
'#type' => 'checkbox',
'#title' => t('Display a textfield quantity widget on the add to cart form.'),
'#default_value' => $this->options['show_quantity'],
);
$form['default_quantity'] = array(
'#type' => 'textfield',
'#title' => t('Default quantity'),
'#default_value' => $this->options['default_quantity'] <= 0 ? 1 : $this->options['default_quantity'],
'#element_validate' => array(
'commerce_cart_field_formatter_settings_form_quantity_validate',
),
'#size' => 16,
);
$form['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' => $this->options['combine'],
);
// Add a conditionally visible line item type element.
$types = commerce_product_line_item_types();
if (count($types) > 1) {
$form['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' => !empty($this->options['line_item_type']) ? $this->options['line_item_type'] : 'product',
);
}
else {
$form['line_item_type'] = array(
'#type' => 'hidden',
'#value' => key($types),
);
}
if ($this->view->display[$this->view->current_display]->display_plugin == 'page') {
$title = t("Link products added to the cart from this page display to the View's path.");
}
else {
$title = t('Link products added to the cart from this display to the current path the customer is viewing where the View is rendered.');
}
$form['display_path'] = array(
'#type' => 'checkbox',
'#title' => $title,
'#default_value' => $this->options['display_path'],
);
}