commerce_avatax.install in Drupal Commerce Connector for AvaTax 8
Same filename and directory in other branches
Provides install and update hooks for Commerce AvaTax.
File
commerce_avatax.installView source
<?php
/**
* @file
* Provides install and update hooks for Commerce AvaTax.
*/
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Field\BaseFieldDefinition;
/**
* Add the "customer_code_field" setting.
*/
function commerce_avatax_update_8101() {
$config = \Drupal::configFactory()
->getEditable('commerce_avatax.settings');
$config
->set('customer_code_field', 'mail')
->save();
}
/**
* Add the "logging" setting.
*/
function commerce_avatax_update_8102() {
$config = \Drupal::configFactory()
->getEditable('commerce_avatax.settings');
$config
->set('logging', FALSE)
->save();
}
/**
* Add the "disable_tax_calculation" setting.
*/
function commerce_avatax_update_8103() {
$config = \Drupal::configFactory()
->getEditable('commerce_avatax.settings');
$config
->set('disable_tax_calculation', FALSE)
->save();
}
/**
* Add the customer exemptions fields to the user.
*/
function commerce_avatax_update_8104() {
$entity_definition_update = \Drupal::entityDefinitionUpdateManager();
$fields = [];
$fields['avatax_customer_code'] = BaseFieldDefinition::create('string')
->setLabel(t('AvaTax customer code'))
->setDisplayConfigurable('form', TRUE)
->setSetting('max_length', 50)
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 0,
]);
$fields['avatax_tax_exemption_number'] = BaseFieldDefinition::create('string')
->setLabel(t('Tax Exemption number'))
->setDisplayConfigurable('form', TRUE)
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 0,
]);
$fields['avatax_tax_exemption_type'] = BaseFieldDefinition::create('list_string')
->setLabel(t('Tax Exemption type'))
->setSetting('allowed_values_function', [
'\\Drupal\\commerce_avatax\\Avatax',
'getExemptionTypes',
])
->setDisplayOptions('form', [
'type' => 'options_select',
'weight' => 4,
])
->setDisplayConfigurable('form', TRUE);
foreach ($fields as $name => $definition) {
try {
$entity_definition_update
->installFieldStorageDefinition($name, 'user', 'commerce_avatax', $definition);
} catch (EntityStorageException $e) {
}
}
}
Functions
Name | Description |
---|---|
commerce_avatax_update_8101 | Add the "customer_code_field" setting. |
commerce_avatax_update_8102 | Add the "logging" setting. |
commerce_avatax_update_8103 | Add the "disable_tax_calculation" setting. |
commerce_avatax_update_8104 | Add the customer exemptions fields to the user. |