Returns the entity bundle info.
string|null $entity_type: The entity type whose bundle info should be returned, or NULL for all bundles info. Defaults to NULL.
array The bundle info for a specific entity type, or all entity types.
function entity_get_bundles($entity_type = NULL) {
$bundles =& drupal_static(__FUNCTION__);
if (!$bundles) {
$langcode = language(Language::TYPE_INTERFACE)->langcode;
if ($cache = cache()
->get("entity_bundle_info:{$langcode}")) {
$bundles = $cache->data;
}
else {
$bundles = module_invoke_all('entity_bundle_info');
// If no bundles are provided, use the entity type name and label.
foreach (entity_get_info() as $type => $entity_info) {
if (!isset($bundles[$type])) {
$bundles[$type][$type]['label'] = $entity_info['label'];
}
}
drupal_alter('entity_bundle_info', $bundles);
cache()
->set("entity_bundle_info:{$langcode}", $bundles, CacheBackendInterface::CACHE_PERMANENT, array(
'entity_info' => TRUE,
));
}
}
if (empty($entity_type)) {
return $bundles;
}
elseif (isset($bundles[$entity_type])) {
return $bundles[$entity_type];
}
return array();
}