You are here

function _commerce_file_create_instance in Commerce File 7

Create a field instance

2 calls to _commerce_file_create_instance()
commerce_file_configure_line_item_type in ./commerce_file.module
Configure a line item type
commerce_file_license_configure_types in includes/commerce_file.entities.inc
Set default fields for license types

File

./commerce_file.module, line 1379
Provides integration of file licenses with Commerce

Code

function _commerce_file_create_instance($field_type, $field_name, $entity_type, $bundle, $options = array()) {

  // If a field type should exist and isn't found, clear the Field cache.
  if (!field_info_field_types($field_type)) {
    field_cache_clear();
  }
  $field = field_info_field($field_name);
  $instance = field_info_instance($entity_type, $field_name, $bundle);
  if (empty($field)) {
    $field = (!empty($options['field']) ? $options['field'] : array()) + array(
      'field_name' => $field_name,
      'type' => $field_type,
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'entity_types' => array(
        $entity_type,
      ),
      'translatable' => FALSE,
      'locked' => FALSE,
      'settings' => array(),
    );
    try {
      $field = field_create_field($field);
    } catch (Exception $e) {
    }
  }
  if (empty($instance)) {
    $instance = (!empty($options['instance']) ? $options['instance'] : array()) + array(
      'field_name' => $field_name,
      'entity_type' => $entity_type,
      'bundle' => $bundle,
      'label' => $field_name,
      'required' => FALSE,
      'settings' => array(),
      'widget' => array(),
      'display' => array(),
    );
    try {
      $instance = field_create_instance($instance);
    } catch (Exception $e) {
    }
  }
}