How to list content entities in Drupal 9?
If you need to get a list of content entitles in your Drupal 9 website for example for drop down on the configuration page you can use the next code snippet
use Drupal\Core\Entity\ContentEntityType;
$content_entities = [];
// Get all entities definitions.
$entity_type_definations = \Drupal::entityTypeManager()->getDefinitions();
foreach ($entity_type_definations as $definition) {
// Check that definition is instance of ContentEntityType
if ($definition instanceof ContentEntityType) {
$content_entities [] = $definition;
}
}