function commerce_vat_field_widget_form_alter in Commerce VAT 7
Implements hook_field_widget_form_alter().
Alter price widgets on the product form to have vat inclusive price entry. This hook was added in Drupal 7.8, so entering prices including VAT will require at least that version.
File
- ./
commerce_vat.module, line 463 - Defines VAT rates and Rules integration for configuring vat rules for applicability and display.
Code
function commerce_vat_field_widget_form_alter(&$element, &$form_state, $context) {
// Act on widgets for fields of type commerce_price on commerce_products.
$direction = variable_get('commerce_vat_direction', 'forward');
if ($context['field']['type'] == 'commerce_price' && $context['instance']['entity_type'] == 'commerce_product' && $direction == 'forward') {
// Build an array of tax types that are display inclusive.
$element['rounded_up'] = array(
'#type' => 'checkbox',
'#title' => t('Rounded Up'),
'#description' => t('This price has been rounded up, calculate VAT on 0.005'),
'#default_value' => isset($element['data']['#default_value']['rounded_up']) ? $element['data']['#default_value']['rounded_up'] : FALSE,
);
$element['#element_validate'][] = 'commerce_vat_price_field_validate';
}
}