You are here

function _commerce_file_get_commerce_file_fields in Commerce File 7

Returns an array of commerce_file field names from a specific entity.

Parameters

$entity_type: The entity type variable passed through hook_field_storage_pre_*() or hook_field_attach_*().

$entity: The entity variable passed through hook_field_storage_pre_*() or hook_field_attach_*().

Return value

array An array of commerce_file field names or an empty array if none are found.

2 calls to _commerce_file_get_commerce_file_fields()
_commerce_file_field_serialize_data in includes/commerce_file.field.inc
Converts commerce_file field data to a serialized array.
_commerce_file_field_unserialize_data in includes/commerce_file.field.inc
Converts saved commerce_file field data columns back to arrays for use in the rest of the current page request execution.

File

includes/commerce_file.field.inc, line 267
Implement an commerce_file field, based on the file module's file field.

Code

function _commerce_file_get_commerce_file_fields($entity_type, $entity) {
  $commerce_file_fields = array();

  // Determine the list of instances to iterate on.
  list(, , $bundle) = entity_extract_ids($entity_type, $entity);
  $instances = field_info_instances($entity_type, $bundle);
  $fields = field_info_fields();

  // Iterate through the instances and collect results.
  foreach ($instances as $instance) {
    $field_name = $instance['field_name'];

    // If the instance is a commerce_file field with data...
    if ($fields[$field_name]['type'] == COMMERCE_FILE_FIELD_TYPE && isset($entity->{$field_name})) {
      $commerce_file_fields[] = $field_name;
    }
  }
  return $commerce_file_fields;
}