I've got a custom entity with bundles that I want to be able to use in an entity reference field in a different entity. So, I've got an the content entity for my entity type:
/**
* Defines the Redacted teaser entity.
*
* @ingroup redacted
*
* @ContentEntityType(
* id = "redacted_teaser",
* label = @Translation("Redacted teaser"),
* bundle_entity_type = "redacted_teaser_bundle",
* bundle_label = @Translation("Content type"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\redacted\RedactedTeaserListBuilder",
* "views_data" = "Drupal\redacted\Entity\RedactedTeaserViewsData",
*
* "form" = {
* "default" = "Drupal\redacted\Entity\Form\RedactedTeaserForm",
* "add" = "Drupal\redacted\Entity\Form\RedactedTeaserForm",
* "edit" = "Drupal\redacted\Entity\Form\RedactedTeaserForm",
* "delete" = "Drupal\redacted\Entity\Form\RedactedTeaserDeleteForm",
* },
* "access" = "Drupal\redacted\RedactedTeaserAccessControlHandler",
* "translation" = "Drupal\node\NodeTranslationHandler",
* },
* base_table = "redacted_teaser",
* admin_permission = "administer RedactedTeaser entity",
* translatable = FALSE,
* entity_keys = {
* "id" = "id",
* "uuid" = "uuid",
* "bundle" = "type",
* "langcode" = "langcode",
* "user_id" = "user_id",
* "created" = "created",
* "changed" = "changed",
* },
* links = {
* "canonical" = "/admin/redacted_teaser/{redacted_teaser}",
* "edit-form" = "/admin/redacted_teaser/{redacted_teaser}/edit",
* "delete-form" = "/admin/redacted_teaser/{redacted_teaser}/delete"
* },
* field_ui_base_route = "entity.redacted_teaser_bundle.edit_form",
* )
*/
And the config entity for my bundles:
/**
* Defines the Redacted teaser bundle entity.
*
* @ConfigEntityType(
* id = "redacted_teaser_bundle",
* label = @Translation("Redacted teaser bundle"),
* bundle_of = "redacted_teaser",
* handlers = {
* "list_builder" = "Drupal\redacted\RedactedTeaserBundleListBuilder",
* "form" = {
* "add" = "Drupal\redacted\Form\RedactedTeaserBundleForm",
* "edit" = "Drupal\redacted\Form\RedactedTeaserBundleForm",
* "delete" = "Drupal\redacted\Form\RedactedTeaserBundleDeleteForm",
* "default" = "Drupal\redacted\Entity\Form\RedactedTeaserForm"
* }
* },
* config_prefix = "redacted_teaser_bundle",
* admin_permission = "administer site configuration",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* },
* links = {
* "canonical" = "/admin/structure/redacted_teaser_bundle/{redacted_teaser_bundle}",
* "edit-form" = "/admin/structure/redacted_teaser_bundle/{redacted_teaser_bundle}/edit",
* "delete-form" = "/admin/structure/redacted_teaser_bundle/{redacted_teaser_bundle}/delete",
* "collection" = "/admin/structure/visibility_group"
* }
* )
*/
I then try to use that in an entity reference field in another entity:
->setSetting('target_type', 'redacted_teaser')
But when I go to create an instance of this entity, the reference field isn't getting any of my bundle instances.
I've also try adding an entity reference field to a content type in the UI. The field settings recognize my defined bundles when I'm setting up the field, but when I go to create a node of that content type the entity reference field doesn't pick up any of my bundles instances there, either. I've compared my annotations to those in Node and NodeType and don't see that I'm missing anything. I've also stepped through with Xdebug, and I can see that when my create form loads, it's getting "redacted_teaser" as the expected type for the reference field.
Everything else about my entity and bundles works just as expected.