You are here

function tca_entity_get_bundle in Token Content Access 7

Gets the bundle of an entity.

Parameters

string $entity_type: The entity type for the entity.

object $entity: The entity that we're checking.

Return value

string The machine name for the bundle.

File

./tca.module, line 428
The Token Content Access module file.

Code

function tca_entity_get_bundle($entity_type, $entity) {
  $entity_info = entity_get_info($entity_type);

  // Use the bundle key to get the bundle for this entity if the bundle key has
  // been defined. If it hasn't, it means that this entity only provides one
  // bundle, and that bundle will always have the same name as the entoty type.
  // E.g, the user entity is built by one bundle, and that bundle is also called
  // user.
  //
  // @see hook_entity_info()
  return !empty($entity_info['entity keys']['bundle']) ? $entity->{$entity_info['entity keys']['bundle']} : $entity_type;
}