Hey there what I'm trying to do is to get all entity type ids from my custom config entity. To load them all.

Example give:

I have an entity 'foo' and I create a new 'foo' named 'bar1' and another 'bar2' and so on how do I get those ids programmatically?

Better question

How do I get all entity_type_ids(or bundles dunno don't found a good entity hirarchie doku yet :( ) of an entity for example all types of the node entity?

  • Are you attempting to perform a query that gets entities of a certain content type and get their ids?
    – Amy
    Commented Jul 29, 2016 at 14:02

2 Answers 2


Do you mean "How do I get an array of all entities of a specific entity type?"

$ids = \Drupal::entityQuery($entity_type_id)->execute();

Because an entity can only be of one type, to get the id of the entity type:

$entity_type_id = $entity->getEntityTypeId();

Answer to the edited question:

"How do I get an array of all bundle id's of a specific entity type?"

$bundles = \Drupal::entityManager()->getBundleInfo($entity_type_id);

Or all content types, which are bundles of the entity type node:

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

This function will be moved to it's own class before Drupal 9:


This is provided as a service:

$content_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('node');

If your entity type was an 'article' for example, you could perform

$query = \Drupal::entityQuery('node')
$nidlist = $query->execute();

$nidlist would then be an array that contains all the IDs in the results in the query.

  • 4
    article is not an entity type, node is. article is a bundle (which is the generic term for what node calls node types)
    – Berdir
    Commented Jul 30, 2016 at 8:32

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.