function commerce_tax_price_field_validate in Commerce Core 7
Validate callback for the tax inclusion select list that serves to reset the data array based on the selected tax.
1 string reference to 'commerce_tax_price_field_validate'
- commerce_tax_field_widget_form_alter in modules/
tax/ commerce_tax.module - Implements hook_field_widget_form_alter().
File
- modules/
tax/ commerce_tax.module, line 421 - Defines tax rates and Rules integration for configuring tax rules for applicability and display.
Code
function commerce_tax_price_field_validate($element, &$form_state) {
// Build an array of form parents to the price array.
$parents = $element['#parents'];
// Get the price array from the form state.
$price = $form_state['values'];
foreach ($parents as $parent) {
$price = $price[$parent];
}
// If a tax was specified...
if (!empty($element['include_tax']['#value'])) {
// Reset the components and store the tax name in the data array.
$price['data']['components'] = array();
$price['data']['include_tax'] = $element['include_tax']['#value'];
}
else {
// Otherwise reset the components array.
$price['data']['components'] = array();
unset($price['data']['include_tax']);
}
// Add the data array to the form state.
$parents[] = 'data';
form_set_value(array(
'#parents' => $parents,
), $price['data'], $form_state);
}