Score:0

What is the use case for "bundle fields" that are independent of an entity type's base fields?

cn flag

So I can define a custom entity in code (quickstart: drush generate entity:content).

I can then use BaseFieldDefinition to define base fields that will be shared by all entities of that type.

However, if my entity has bundles, I may want to define some fields only for certain bundles. It seems this is sometimes called a "bundle field" on drupal.org, and they can be defined in hook_entity_bundle_field_info(), but they:

need to provide a field storage definition via hook_entity_field_storage_info() unless they are computed.

As noted in the docs this API is not yet finalized.

Could someone please explain why I might want to define a "bundle field" using hook_entity_bundle_field_info() and hook_entity_field_storage_info() together instead of using the Field UI to add fields to bundles? Is there any performance benefit to doing it this way, or is this approach strictly for module developers to add fields to entity bundles that they are shipping with the modules?

4uk4 avatar
cn flag
You can ship config with modules as well.
miststudent2011 avatar
fr flag
@4uk4 isnt the whole point of bundle class and bundle fields is to eliminate shipping of config in module?
miststudent2011 avatar
fr flag
I believe bundle claases are not mature enough to replace shipping of config as I can not find single instance where it worked for custom entity, you can observe same on CR as well https://www.drupal.org/node/3191609
miststudent2011 avatar
fr flag
Related https://drupal.stackexchange.com/q/312015/71454
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.