drupal-console
drupal-console copied to clipboard
[generate:entity:bundle] allow to add bundles to non-node entity types
Problem/Motivation
When using generate:entity:bundle we hope to create an entity bundle, not a node type. It could be used to create any other entity bundle.
How to reproduce
Launch the command, follow the steps, wait to be asked which entity type we want to extend.
- Drupal version 8.3.4
- Console version 1.0.0-rc23
- Console Launcher version 1.0.0-rc23
Solution
Add one more step to ask for the entity type then check if this type has bundles.
I second this. Is there a way to generate new entity types that are not node content types?
When I use the --has-bundles flag for generate:entity:content, this results in a module that at first appears to have bundles, but then if you create two bundles through the UI, and add a field to one of the bundles, it will also appear in the other bundle. It's not immediately clear what would be the next step to make it so I can configure the fields for each bundle independently.
In the meantime, this appears to be a good guide to creating an entity with bundles: https://www.daggerhart.com/drupal-8-custom-entities-bundles/
Here is a guide that appears relevant. https://www.agoradesign.at/blog/how-create-custom-entities-bundle-support-drupal-8
Update: I have confirmed that the approach described in the agoradesign.at guide works.
Under "Creating the boilerplate code", you have to do steps 1-3. Step 4 doesn't seem to be necessary, but I'm not sure.
For steps 1-3, you use these commands...
drupal generate:module
drupal generate:entity:config
drupal generate:entity:content
Then you can move on to the "Add bundle capability" section. One thing the guide does not mention is that if you want fieldable entities, you need to add this to your entity type annotation where you extendConfigEntityBundleBase:
fieldable = TRUE,
+1 here, it does seem very strange that there's this option...
generate:entity:bundle (geb) Generate a new content type (node / entity bundle)
And then you're greeted with
Enter the machine name of your new content type [default]:
Hi,
I'm searching too the way to generate bundles (or entity types) for custom entities... Let say I want to create a new entity : "vehicle". I create it this way : First my custom module :
drupal generate:module --module="Vehicles" --machine-name="vehicles" --module-path="modules/custom" --core="8.x" --package="Custom" --module-file --composer --test=1 --twigtemplate=1 --no-interaction --yes;
Then my custom entity :
drupal generate:entity:content --module="vehicles" --entity-class="Vehicle" --entity-name="vehicle" --label="vehicle" --base-path="/admin/structure" --has-bundles --is-translatable --revisionable --no-interaction --yes;
And now I want to generate the code or configurations for two bundles : truck an car. I tried this way :
drupal generate:entity:bundle --module="vehicles" --bundle-name="car" --bundle-title="Car"
But there is no mention of entity here...
Thanks for your help,