You are here

function _commerce_avatax_configure_vat_id_field in Drupal Commerce Connector for AvaTax 7.5

Helper function : Configure the VAT ID field.

1 call to _commerce_avatax_configure_vat_id_field()
commerce_avatax_install_helper in ./commerce_avatax.install
Helper function to define and create the required fields & instances.

File

./commerce_avatax.install, line 237
Installation functions for Commerce Avatax module.

Code

function _commerce_avatax_configure_vat_id_field() {
  $field_name = COMMERCE_AVATAX_VAT_ID_FIELD;
  $add_vat_field = variable_get(COMMERCE_AVATAX_VAR_PREFIX . 'add_vat_field', 0);

  // Delete the field if it exist.
  if (!$add_vat_field) {
    $instance = field_info_instance('user', $field_name, 'user');
    if ($instance) {
      field_delete_instance($instance);
    }
  }
  else {

    // Create the field and instance if they do not exist.
    $field = field_info_field($field_name);
    if (!$field) {
      field_create_field(array(
        'cardinality' => 1,
        'field_name' => $field_name,
        'type' => 'text',
      ));
    }
    $instance = field_info_instance('user', $field_name, 'user');
    if (!$instance) {
      field_create_instance(array(
        'bundle' => 'user',
        'display' => array(),
        'entity_type' => 'user',
        'field_name' => $field_name,
        'label' => 'VAT ID',
        'required' => 0,
        'settings' => array(
          'user_register_form' => 0,
        ),
        'widget' => array(
          'active' => 1,
          'module' => 'text',
          'settings' => array(),
          'type' => 'text_textfield',
          'weight' => 7,
        ),
      ));
    }
  }
}