As mentioned by eaton in http://forrst.com/posts/Get_the_bundle_of_a_Drupal_7_entity-0xW, this would be a very useful helper to have in Entity API:
function _entity_get_bundle($entity, $entity_type) {
$info = entity_get_info($entity_type);
if (empty($info['entity keys']['bundle'])) {
return $entity_type;
} else {
return $entity->{$info['entity keys']['bundle']};
}
}
Comments
Comment #1
joachim commented... except the params should be other way round to match all the other functions that take ($entity_type, $entity), and the else shouldn't be coddled...
Comment #2
fagoWell, there is entity_extract_ids() in core..
Comment #3
fagoStill, for classed entity objects a bundle() helper method was missing. I've added one, as we've in d8 core now.