I'd like to use bundle classes with taxonomy vocabularies. Vocabularies are bundleable config entities inheriting from EntityBase just like nodes, term and other content entities. The doc states bundle classes should work with all entities that are a subclass of the base entity class, but I can't get it to work with config entities.
works:
function foo_entity_bundle_info_alter(&$bundles) {
if (isset($bundles['taxonomy_term']['foo'])) {
$bundles['taxonomy_term']['foo']['class'] = TermFoo::class;
}
}
\Drupal::entityTypeManager()->getStorage('taxonomy_term')->load(123)
does not work:
function bar_entity_bundle_info_alter(&$bundles) {
if (isset($bundles['taxonomy_vocabulary']['bar'])) {
$bundles['taxonomy_vocabulary']['bar']['class'] = VocabularyBar::class;
}
}
\Drupal::entityTypeManager()->getStorage('taxonomy_vocabulary')->load('bar')
During debugging I noticed that the hook's parameter $bundles['taxonomy_term']
had all bundles as sub-keys, matching the recommended if-statement.
But $bundles['taxonomy_vocabulary']
was missing all bundles, it only had a single sub-key $bundles['taxonomy_vocabulary']['taxonomy_vocabulary']
, no bundles as keys anywhere, so the bundle class was never injected.
I then tried some dumb things in good faith like
function bar_entity_bundle_info_alter(&$bundles) {
$bundles['taxonomy_vocabulary']['bar']['class'] = VocabularyBar::class;
}
or
function bar_entity_bundle_info_alter(&$bundles) {
if (isset($bundles['taxonomy_vocabulary']['bar'])) {
$bundles['taxonomy_vocabulary']['taxonomy_vocabulary']['bar']['class'] = VocabularyBar::class;
}
}
but of course this did not work.
Is the doc simply incorrect or what am I missing to use bundle classes with config entities?