I've got a custom content type (generated by drush) that extends ContentEntityBase and a bundle class (also generated by drush) that extends my content type. I've registered my bundle with hook_entity_bundle_info() in my_module.module, and the entity type bundle service shows my bundle belonging to my content type:
>>> $bundleInfo = \Drupal::service('entity_type.bundle.info')
=> Drupal\Core\Entity\EntityTypeBundleInfo {#1475
+"_serviceId": "entity_type.bundle.info",
}
>>> $bundles = $bundleInfo->getBundleInfo('my_content_type')
=> [
"my_content_type" => [],
"dc_thing" => [
"label" => Drupal\Core\StringTranslation\TranslatableMarkup {#5566},
"class" => "Drupal\my_module\Entity\Bundle\DcThing",
],
]
But when I try creating an entity using my dc_thing bundle, Drupal complains that my content type is missing a bundle
>>> $etm = \Drupal::service('entity_type.manager')
=> Drupal\Core\Entity\EntityTypeManager {#996
+"_serviceId": "entity_type.manager",
}
>>> $thing = $etm->getStorage('my_content_type')->create(['type' => 'dc_thing', 'label' => 'Particle Mang'])
Drupal\Core\Entity\EntityStorageException with message 'Missing bundle for entity type my_content_type'
All of the example code I've been able to find for bundle classes extend Node, but as far as I'm aware, the only bundles for Node in core are for Article and Basic Page, I don't see where there's a bundle defined for the Node entity type.
>>> $article = $etm->getStorage('node')->create(['type' => 'article', 'label' => 'test article'])
works just fine.