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.
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.
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.