Drupal - How do I get a list of bundles?

To get the bundles for an entity type, use the entity_type.bundle.info service, like this:

\Drupal::service('entity_type.bundle.info')->getBundleInfo('ENTITY_TYPE')

or use dependency injection to inject the service.

See the documentation for getBundleInfo for more information.


If you want to get bundles of an entity type via drush the command is

drush php-eval "print_r(array_keys(\Drupal::service('entity_type.bundle.info')->getBundleInfo('ENTITY_TYPE')));"

Tags:

Entities

8