You are here

function commerce_cardonfile_flush_caches in Commerce Card on File 7.2

Implements hook_flush_caches().

Creates the commerce_cardonfile_profile field on the commerce_cardonfile entity type if missing.

File

./commerce_cardonfile.module, line 183
Supports card on file functionality for credit card payment methods by associating card data reference IDs from payment gateways with user accounts.

Code

function commerce_cardonfile_flush_caches() {
  $field = field_info_field('commerce_cardonfile_profile');
  if (!$field) {
    $field = array(
      'field_name' => 'commerce_cardonfile_profile',
      'type' => 'commerce_customer_profile_reference',
      'cardinality' => 1,
      'entity_types' => array(
        'commerce_cardonfile',
      ),
      'translatable' => FALSE,
      'settings' => array(
        'profile_type' => 'billing',
      ),
    );
    $field = field_create_field($field);
  }
  $instance = field_info_instance('commerce_cardonfile', 'commerce_cardonfile_profile', 'commerce_cardonfile');
  if (!$instance) {
    $instance = array(
      'field_name' => 'commerce_cardonfile_profile',
      'entity_type' => 'commerce_cardonfile',
      'bundle' => 'commerce_cardonfile',
      'label' => 'Billing Profile',
      'widget' => array(
        'type' => 'commerce_customer_profile_manager',
        'weight' => -5,
      ),
      'display' => array(),
    );

    // Set the default display formatters for various view modes.
    foreach (array(
      'default',
      'customer',
      'administrator',
    ) as $view_mode) {
      $instance['display'][$view_mode] = array(
        'label' => 'above',
        'type' => 'commerce_customer_profile_reference_display',
        'weight' => -5,
      );
    }
    field_create_instance($instance);
  }
}