You are here

function commerce_tax_ui_tax_type_save in Commerce Core 7

Saves a tax type.

This function will either insert a new tax type if $tax_type['is_new'] is set or attempt to update an existing tax type if it is not. It does not currently support changing the machine-name of the tax type, nor is this possible through the form supplied by the Tax UI module.

Parameters

$tax_type: The tax type array containing the basic properties as initialized in commerce_tax_ui_tax_type_new().

$skip_reset: Boolean indicating whether or not this save should result in entities being reset and the menu being rebuilt; defaults to FALSE. This is useful when you intend to perform many saves at once, as menu rebuilding is very costly in terms of performance.

Return value

The return value of the call to drupal_write_record() to save the tax type, either FALSE on failure or SAVED_NEW or SAVED_UPDATED indicating the type of query performed to save the tax type.

3 calls to commerce_tax_ui_tax_type_save()
CommerceBaseTestCase::createDummyTaxType in tests/commerce_base.test
* Create a dummy tax type. * *
commerce_tax_ui_install in modules/tax/commerce_tax_ui.install
Implements hook_install().
commerce_tax_ui_tax_type_form_submit in modules/tax/includes/commerce_tax_ui.admin.inc
Form submit handler: save a tax type.

File

modules/tax/commerce_tax_ui.module, line 287
Provides a UI for creating simple tax types and rates.

Code

function commerce_tax_ui_tax_type_save($tax_type, $skip_reset = FALSE) {
  $op = drupal_write_record('commerce_tax_type', $tax_type, empty($tax_type['is_new']) ? 'name' : array());
  commerce_tax_types_reset();

  // If this is a new tax type and the insert did not fail...
  if (!empty($tax_type['is_new']) && $op !== FALSE) {

    // Notify other modules that a new tax type has been created.
    module_invoke_all('commerce_tax_type_insert', $tax_type, $skip_reset);
  }
  elseif ($op !== FALSE) {

    // Notify other modules that an existing tax type has been updated.
    module_invoke_all('commerce_tax_type_update', $tax_type, $skip_reset);
  }

  // Clear the necessary caches and rebuild the menu items.
  if (!$skip_reset) {
    entity_defaults_rebuild();
    rules_clear_cache(TRUE);
    variable_set('menu_rebuild_needed', TRUE);
  }
  return $op;
}