Given a custom defined entity 'Foo', how can I make a bundle programmatically?
Such as Node entity has the Article and Basic page bundles (with fields) on install.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
Bundles are configuration.
You define a config entity with the name of the bundle of the custom entity:
class FooType extends ConfigEntityBundleBase
Then you can create a new bundle:
$bundle = FooType::create([ 'id' => 'newbundle', 'label' => 'New Bundle', 'revision' => FALSE, ]); $bundle->save();
Bundles usually are not created programmatically. Most times modules put bundles in /config/install as yml files.