You are here

function commerce_physical_entity_field_name in Commerce Physical Product 7

Determines the field of a certain type to use for a given entity.

Parameters

string $entity_type: The type of entity passed to the function.

object $entity: The actual entity whose weight field name should be determined.

string $field_type: The field type to use.

Return value

string The name of the field to use on the entity to find a weight value or NULL if none was found.

2 calls to commerce_physical_entity_field_name()
commerce_physical_entity_dimensions_field_name in ./commerce_physical.module
Determines the dimensions field to use for a given entity.
commerce_physical_entity_weight_field_name in ./commerce_physical.module
Determines the weight field to use for a given entity.

File

./commerce_physical.module, line 67
API for working with physical product types in Drupal Commerce.

Code

function commerce_physical_entity_field_name($entity_type, $entity, $field_type) {
  $bundle = field_extract_bundle($entity_type, $entity);
  $field_name = NULL;

  // Look for the first field available for the entity.
  foreach (field_info_instances($entity_type, $bundle) as $instance_name => $instance) {

    // Load the field info for the current instance.
    $field = field_info_field($instance['field_name']);

    // If it's of the proper type...
    if ($field['type'] == $field_type) {

      // Save its name and exit the loop.
      $field_name = $instance_name;
      break;
    }
  }
  return $field_name;
}