Getting the bundle of nodes or terms

Sometimes it is helpful to figure out what kind of bundle you are working with. On a node, the bundle would be the content type machine name of the node, (ex: article, info...) On a term page the bundle would be the actual vocabulary machine name of the vocabulary (ex: activities, cities, regions,)

Calling this function on the loaded entity will return the bundle name.

// Get the bundle name of the node or vocabulary
$sBundle = get_entity_bundle($oEntity);


Here is the code of the function:

 * Get the bundle of object you are on by node type, vocabulary machine name or NULL
 * @param $oEntity object of the fully loaded entity
 * @return string representing either the node bundle(type), the vocabulary machine name or NULL if neither.
function get_entity_bundle($oEntity){
//check to see if it is a node or a term
if (!empty($oEntity->vocabulary_machine_name)){
//Means this is a vocabulary term page
$sBundle = $oEntity->vocabulary_machine_name;
        } else if (!empty(
//Means this is a node  
$sBundle = $oEntity->type;
        } else {
$sBundle = NULL;

        return $sBundle;
// get_entity_bundle