function commerce_stock_custom_cart_form_state in Commerce Stock 7.2
Custom cart form state.
@todo: Define this function.
1 string reference to 'commerce_stock_custom_cart_form_state'
- commerce_stock_rules_action_info in ./
commerce_stock.rules.inc - Implements hook_rules_action_info().
File
- ./
commerce_stock.rules.inc, line 323 - Rules integration for Commerce Stock.
Code
function commerce_stock_custom_cart_form_state($hide_qty, $text, $class_name, $action_prefix, $action_suffix, $stock_action, $disabled_cart, $custom_submit, $custom_submit_clear, $custom_validate, $custom_validate_clear, $custom_url, $custom_html) {
// @codingStandardsIgnoreLine
global $stock_cart_check_data;
// Read form values.
$form_action = $stock_cart_check_data['form']['#action'];
if (isset($stock_cart_check_data['form']['product_id']['#value'])) {
$prod_id = $stock_cart_check_data['form']['product_id']['#value'];
}
elseif (isset($stock_cart_check_data['form']['product_id']['#default_value'])) {
$prod_id = $stock_cart_check_data['form']['product_id']['#default_value'];
}
// Class.
$stock_cart_check_data['form']['#attributes']['class']['stock'] = $class_name;
// Quantity field.
if ($hide_qty) {
$stock_cart_check_data['form']['quantity']['#access'] = FALSE;
}
// Prefix & suffix.
$stock_cart_check_data['form']['submit']['#prefix'] = $action_prefix;
$stock_cart_check_data['form']['submit']['#suffix'] = $action_suffix;
switch ($stock_action) {
// Normal Submit.
case 0:
$stock_cart_check_data['form']['submit']['#value'] = $text;
$stock_cart_check_data['form']['submit']['#disabled'] = $disabled_cart;
break;
// Custom Submit.
case 1:
$stock_cart_check_data['form']['submit']['#value'] = $text;
// Should we clear the submit array.
if ($custom_submit_clear) {
$stock_cart_check_data['form']['#submit'] = array();
}
// Should we clear the validate array.
if ($custom_validate_clear) {
$stock_cart_check_data['form']['#validate'] = array();
}
// Add custom submit function.
if (!empty($custom_submit)) {
$stock_cart_check_data['form']['#submit'][] = $custom_submit;
}
// Sdd custom validation function.
if (!empty($custom_validate)) {
$stock_cart_check_data['form']['#validate'][] = $custom_validate;
}
break;
// URL Action.
case 2:
if (!empty($custom_url)) {
// Custom url.
$custom_url = str_replace('[product_id]', $prod_id, $custom_url);
$custom_url = str_replace('[url]', $form_action, $custom_url);
$stock_cart_check_data['form']['submit']['#type'] = 'link';
$stock_cart_check_data['form']['submit']['#title'] = $text;
$stock_cart_check_data['form']['submit']['#href'] = $custom_url;
}
break;
// Custom HTML.
case 3:
if (!empty($custom_html)) {
// Custom url.
$custom_html = str_replace('[product_id]', $prod_id, $custom_html);
$custom_html = str_replace('[url]', $form_action, $custom_html);
$stock_cart_check_data['form']['submit']['#type'] = 'markup';
$stock_cart_check_data['form']['submit']['#markup'] = $custom_html;
}
break;
default:
break;
}
}