I want to get bundleKey of any entity type after is loading from

$node = \Drupal::entityManager()->getStorage('node');

After getStorage I am getting bundleKey Value as "type", but how to render that, as it is saying that is a protected value. Tried to fetch like:

-> $node->get('bundleKey')->Value();
-> $node->getField('bundleKey')->getValue();
-> $node->bundleKey;

All above methods i tried to fetch Values but still no luck.

Anyone Knows how to fetch bundleKey.

2 Answers 2


You can get bundleKey of your entity type by this way:

$type = 'commerce_product';
$bundle_key = \Drupal::entityTypeManager()->getDefinition($type)->getKey('bundle');

Found Solution:

Rather that loading complete storage, we can use entityDefinitionUpdateManager and get keys where you will get all id, bundle, label, etc

$manager = \Drupal::entityTypeManager();
$entity_type = $manager->getEntityType('commerce_product');
$entity_keys = $entity_type->getKeys();
$bundle = $entity_keys['bundle'];
  • 1
    the same is available as entity type manager getDefinition, do not use the definition update manager. Also, what are you trying to do exactly? why do you need the name of that? You can ust use $entity->bundle() on any entity to get the value. Also $entity_type->getKey('bundle'). Note that not all entity types have this.
    – Berdir
    Commented Aug 27, 2016 at 11:48
  • @Berdir: Updated answer. I am trying to get bundleKey, and I am doing this as one of my module requires to use entity query condition. Yes every entity type doesn't have bundleKey , i need only for node, taxonomy and commerce entities to load dynamically.
    – Ajay Reddy
    Commented Aug 27, 2016 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.