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?