You are here

function commerce_file_license_configure_types in Commerce File 7

Set default fields for license types

1 call to commerce_file_license_configure_types()
commerce_file_enable in ./commerce_file.module
Implements hook_enable().

File

includes/commerce_file.entities.inc, line 641
Handles file licenses and file license logs

Code

function commerce_file_license_configure_types($type = COMMERCE_FILE_LICENSE_ENTITY_NAME) {

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

  // entity info
  $entity_type = COMMERCE_FILE_LICENSE_ENTITY_NAME;
  $bundle = $type;
  $field_names = _commerce_file_get_field_names();

  // File reference
  _commerce_file_create_instance(COMMERCE_FILE_FIELD_TYPE, $field_names['license_file'], $entity_type, $bundle, array(
    'field' => array(
      'cardinality' => 1,
      'locked' => FALSE,
      'settings' => array(
        'uri_scheme' => _commerce_file_default_system_scheme(),
      ),
    ),
    'instance' => array(
      'label' => 'Licensed file',
      'required' => TRUE,
      'settings' => array(
        'file_extensions' => 'mp4 m4v flv wmv mp3 wav jpg jpeg png pdf doc docx ppt pptx xls xlsx',
        'file_directory' => 'commerce-files',
        'max_filesize' => '',
      ),
      'widget' => array(
        'type' => 'commerce_file_generic',
        'weight' => 10,
      ),
      'display' => array(
        'default' => array(
          'label' => 'hidden',
        ),
      ),
    ),
  ));

  // Line item references - locked

  /** @todo make this a custom line item reference to allow admins to add lines to a license - ie. a non line item manager widget ********/
  _commerce_file_create_instance('commerce_line_item_reference', $field_names['license_line_items'], $entity_type, $bundle, array(
    'field' => array(
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'locked' => TRUE,
    ),
    'instance' => array(
      'label' => 'Line item references',
      'widget' => array(
        'type' => 'commerce_line_item_manager',
        'weight' => -10,
      ),
      'display' => array(
        'default' => array(
          'label' => 'above',
          'type' => 'commerce_line_item_reference_view',
          'weight' => 10,
        ),
      ),
    ),
  ));
}