You are here

static function MigrateDestinationCommerceProductType::createFieldImageInstance in Commerce Migrate 7

File

plugins/destinations/commerce_product_type.inc, line 188
Support for commerce product types.

Class

MigrateDestinationCommerceProductType
Destination class implementing migration into commerce product types.

Code

static function createFieldImageInstance($bundle_name, $field_name) {
  $entity_type = 'commerce_product';

  // If a field type we know should exist isn't found, clear the Field cache.
  if (!field_info_field_types('image')) {
    field_cache_clear();
  }

  // Look for or add the specified price field to the requested entity bundle.
  $field = field_info_field($field_name);

  // If the field type does not already exist, create it.
  if (empty($field)) {
    $field = array(
      'field_name' => $field_name,
      'type' => 'image',
      'cardinality' => -1,
      'translatable' => TRUE,
      'locked' => FALSE,
      'indexes' => array(
        'fid' => array(
          'fid',
        ),
      ),
      'settings' => array(
        'uri_scheme' => 'public',
        'default_image' => FALSE,
      ),
      'storage' => array(
        'type' => 'field_sql_storage',
        'settings' => array(),
      ),
    );
    field_create_field($field);
  }
  $instance = field_info_instance($entity_type, $field_name, $bundle_name);
  if (empty($instance)) {
    $instance = array(
      'field_name' => $field_name,
      'entity_type' => $entity_type,
      'label' => $field_name . ' ' . t('Image'),
      'bundle' => $bundle_name,
      'description' => t('Upload an image of this product.'),
      'required' => FALSE,
      'settings' => array(
        'file_directory' => "field/{$field_name}",
        'file_extensions' => 'png gif jpg jpeg',
        'max_filesize' => '',
        'max_resolution' => '',
        'min_resolution' => '',
        'alt_field' => TRUE,
        'title_field' => '',
      ),
      'widget' => array(
        'type' => 'image_image',
        'settings' => array(
          'progress_indicator' => 'throbber',
          'preview_image_style' => 'thumbnail',
        ),
        'weight' => -1,
      ),
      'display' => array(
        'default' => array(
          'label' => 'hidden',
          'type' => 'image',
          'settings' => array(
            'image_style' => 'large',
            'image_link' => '',
          ),
          'weight' => -1,
        ),
        'teaser' => array(
          'label' => 'hidden',
          'type' => 'image',
          'settings' => array(
            'image_style' => 'medium',
            'image_link' => 'content',
          ),
          'weight' => -1,
        ),
      ),
    );
    field_create_instance($instance);
  }
}