function field_extract_bundle

8.x field.module field_extract_bundle($entity_type, $bundle)

Extracts the bundle name from a bundle object.


$entity_type: The type of $entity; e.g., 'node' or 'user'.

$bundle: The bundle object (or string if bundles for this entity type do not exist as standalone objects).

Return value

The bundle name.

Related topics

1 call to field_extract_bundle()
field_ui_instance_load in drupal/core/modules/field_ui/field_ui.module
Menu loader callback: Loads a field instance based on field and bundle name.


drupal/core/modules/field/field.module, line 972
Attach custom data fields to Drupal entities.


function field_extract_bundle($entity_type, $bundle) {
  if (is_string($bundle)) {
    return $bundle;

  $info = entity_get_info($entity_type);
  if (is_object($bundle) && isset($info['bundle_keys']['bundle']) && isset($bundle->{$info['bundle_keys']['bundle']})) {
    return $bundle->{$info['bundle_keys']['bundle']};