I have custom fields that I need to add to specific entity types and bundles with hook_entity_bundle_field_info()
. However, I have to decide on which one to add depending on already existing fields, hence I need to ask for those. The hook function only receives the base field definitions passed as an argument, not the bundle fields. And, unfortunately, it seems I cannot use \Drupal::service('entity_field.manager')->getFieldDefinitions()
from inside hook_entity_bundle_field_info()
because it leads to an out-of-memory error, as it very probably calls itself repeatedly.
How can I make decisions depending on the presence and settings (eg. enabled status) of already existing fields?