You are here

function commerce_tax_ui_tax_rate_form in Commerce Core 7

Form callback: create or edit a tax rate.

Parameters

$tax_rate: The tax rate array to edit or for a create form an empty tax rate array with properties instantiated but not populated.

2 string references to 'commerce_tax_ui_tax_rate_form'
commerce_tax_ui_menu in modules/tax/commerce_tax_ui.module
Implements hook_menu().
commerce_tax_ui_tax_rate_add_form_wrapper in modules/tax/includes/commerce_tax_ui.admin.inc
Form callback wrapper: ensure tax types exist before going to the add form.

File

modules/tax/includes/commerce_tax_ui.admin.inc, line 133
Administrative callbacks and form builder functions for the Tax UI module.

Code

function commerce_tax_ui_tax_rate_form($form, &$form_state, $tax_rate) {

  // Store the initial tax rate in the form state.
  $form_state['tax_rate'] = $tax_rate;
  $form['tax_rate'] = array(
    '#tree' => TRUE,
  );
  $form['tax_rate']['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $tax_rate['title'],
    '#description' => t('The administrative title of this tax rate. It is recommended that this title begin with a capital letter and contain only letters, numbers, and spaces.'),
    '#required' => TRUE,
    '#size' => 32,
    '#field_suffix' => ' <small id="edit-tax-rate-title-suffix">' . t('Machine name: @name', array(
      '@name' => $tax_rate['name'],
    )) . '</small>',
  );
  if (empty($tax_rate['name'])) {
    $form['tax_rate']['name'] = array(
      '#type' => 'machine_name',
      '#title' => t('Machine name'),
      '#default_value' => $tax_rate['name'],
      '#maxlength' => 46,
      '#required' => TRUE,
      '#machine_name' => array(
        'exists' => 'commerce_tax_rate_load',
        'source' => array(
          'tax_rate',
          'title',
        ),
      ),
      '#description' => t('The machine-name of this tax rate. This name must contain only lowercase letters, numbers, and underscores. It must be unique.'),
    );
  }
  $form['tax_rate']['display_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Display title'),
    '#default_value' => $tax_rate['display_title'],
    '#description' => t('The front end display title of this tax rate shown to customers. Leave blank to default to the <em>Title</em> from above.'),
    '#size' => 32,
  );
  $form['tax_rate']['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#description' => t('Describe this tax rate if necessary. The text will be displayed in the tax rate overview table.'),
    '#default_value' => $tax_rate['description'],
    '#rows' => 3,
  );
  $form['tax_rate']['rate'] = array(
    '#type' => 'textfield',
    '#title' => t('Rate', array(), array(
      'context' => 'tax rate',
    )),
    '#description' => t('The percentage used to calculate this tax expressed as a decimal, e.g. .06 for a rate of 6%.'),
    '#default_value' => $tax_rate['rate'],
    '#size' => 16,
    '#required' => TRUE,
  );
  $form['tax_rate']['type'] = array(
    '#type' => 'select',
    '#title' => t('Type'),
    '#description' => t('The tax type for this rate.'),
    '#options' => commerce_tax_type_titles(),
    '#default_value' => $tax_rate['type'],
    '#required' => TRUE,
  );
  $form['actions'] = array(
    '#type' => 'actions',
    '#weight' => 40,
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save tax rate'),
  );
  if (!empty($form_state['tax_rate']['name'])) {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete tax rate'),
      '#suffix' => l(t('Cancel'), 'admin/commerce/config/taxes'),
      '#submit' => array(
        'commerce_tax_ui_tax_rate_form_delete_submit',
      ),
      '#weight' => 45,
    );
  }
  else {
    $form['actions']['submit']['#suffix'] = l(t('Cancel'), 'admin/commerce/config/taxes');
  }
  return $form;
}