Title likely sounds confusing. Let me explain.

I am putting together a module which has a custom field which can be assigned to any "content type" which is fieldable. As an example, this could include node, users, taxonomy terms, etc.

Within the module i need to do things like: get entities in specific bundle, get bundle display name, etc.

In my code i use a loop through entityManager()->getFieldMap() to get a list of entity_type.bundles that have my custom field attached, so for my example site i have:



"node.user" (yes, i created a node bundle called "User")

"user.user" (user type has a fake bundle called user - or does it??)

This code works fine and suggests that Drupal standardizes its entity interface by providing a pseudo bundle for types which do not have bundles (such as users). But is this really the case?

In my code i need to do a query to pull entities in these bundles. For nodes i include ->condition('type', $bundle), but this will not work for user type and throws an error saying no column type for users.

I also need to display the "bundles" display name: Camera, Room, User, etc; but again, i need to use different code for each of these:

node: $entity->type->entity->label();
user: $entity->getEntityType()->getLabel()->__toString();

and, I have pretty bad code to decide which of these i use: i simply check if bundle name and entity name are the same; which will fail if i make a node bundle called Node.

So, 2 questions:

1. are there generic methods that are bundle agnostic to do things like get "bundle entities" and display name?

2. is there a proper API call to determine if a type has bundles?