Helper function to extract the bundle name of from a bundle object.
$entity_type: The type of $entity; e.g., 'node' or 'user'.
$bundle: The bundle object (or string if bundles for this entity type do not exist as standalone objects).
The bundle name.
function field_extract_bundle($entity_type, $bundle) {
if (is_string($bundle)) {
return $bundle;
}
$info = entity_get_info($entity_type);
if (is_object($bundle) && isset($info['bundle keys']['bundle']) && isset($bundle->{$info['bundle keys']['bundle']})) {
return $bundle->{$info['bundle keys']['bundle']};
}
}