You are here

function _commerce_coupon_user_install_helper in Commerce Coupon 7.2

Field setup

2 calls to _commerce_coupon_user_install_helper()
commerce_coupon_user_flush_caches in modules/user/commerce_coupon_user.module
Implements hook_flush_caches().
commerce_coupon_user_install in modules/user/commerce_coupon_user.install

File

modules/user/commerce_coupon_user.install, line 18
Installation tasks for Commerce Coupon User.

Code

function _commerce_coupon_user_install_helper() {
  field_info_cache_clear();
  $fields = field_info_fields();
  $instances = field_info_instances();

  // Add an entity reference field for recipient.
  if (empty($fields['commerce_coupon_recipient'])) {
    $field = array(
      'settings' => array(
        'target_type' => 'user',
      ),
      'field_name' => 'commerce_coupon_recipient',
      'type' => 'entityreference',
      'cardinality' => '1',
    );
    field_create_field($field);
  }
  foreach (commerce_coupon_get_types() as $bundle => $info) {
    if (empty($instances['commerce_coupon'][$bundle]['commerce_coupon_recipient'])) {
      $instance = array(
        'label' => 'Recipient',
        'widget' => array(
          'type' => 'entityreference_autocomplete',
          'weight' => '10',
        ),
        'description' => 'Choose a recipient for this coupon code',
        'field_name' => 'commerce_coupon_recipient',
        'entity_type' => 'commerce_coupon',
        'bundle' => $bundle,
        'default_value' => NULL,
      );
      field_create_instance($instance);
    }
  }
}