function rich_snippets_extract_bundle in Rich Snippets 7
Helper function to get the entity's bundle.
Is there really no API function to get an entity's bundle? I must have missed it.
Parameters
string $entity_type: The machine name of the entity.
stdClass $entity: The entity the bundle is being extracted from.
Return value
string|FALSE The machine name of the bundle, FALSE if the bundle couldn't be extracted.
2 calls to rich_snippets_extract_bundle()
- rich_snippets_apachesolr_index_document_build in ./
rich_snippets.apachesolr.inc - Implements hook_apachesolr_index_document_build().
- rich_snippets_has_schemaorg_mapping in ./
rich_snippets.apachesolr.inc - Returns TRUE if the field is mapped to a Schema.org schema or property.
File
- ./
rich_snippets.apachesolr.inc, line 278 - Apache Solr Search Integration hook implementations and helper functions.
Code
function rich_snippets_extract_bundle($entity_type, $entity) {
$bundle = FALSE;
if ($entity_info = entity_get_info($entity_type)) {
// Attempt to extract the bundle from the entity keys. Make sure that the
// entity we extracted is valid just in case.
if (isset($entity_info['bundle keys'])) {
foreach ($entity_info['bundle keys'] as $key) {
if (isset($entity->{$key}) && isset($entity_info['bundles'][$entity->{$key}])) {
$bundle = $entity->{$key};
break;
}
}
}
}
return $bundle;
}