0

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?

4
  • You can ship config with modules as well.
    – 4uk4
    Oct 8, 2022 at 11:57
  • @4uk4 isnt the whole point of bundle class and bundle fields is to eliminate shipping of config in module? Oct 8, 2022 at 16:39
  • 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 drupal.org/node/3191609 Oct 8, 2022 at 16:41
  • Related drupal.stackexchange.com/q/312015/71454 Oct 8, 2022 at 16:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.