Somewhat the continuation of Getting existing fields in hook_entity_bundle_field_info() with a similar problem. I'm using this hook now to make modifications not only to the bundle fields but their form and view settings as well. The probem I face is similar: it's restricted what queries I can make from this hook. This time it's using the entity_display.repository
service. getViewModes()
works but reading the config data with getViewDisplay()
leads to the same infinite loop. I also tried workarounds -- \Drupal::entityQuery('entity_view_display')
and getting the same storage on the entity type manager but, as they probably all lead to the same code, anyway, all three blow up.
And this time, it doesn't look like my oversight of not using the right hook. There's no direct hook for the view and form displays documented anywhere. The view modes have one but they only get the modes, not the displays, that's different. Yes, I know of hook_entity_view_display_alter()
but this time this is a real alter()
, not an info_alter()
, it only influences the actual display, I tried, just like its form display counterpart.
The core node
module has something remotely similar, node_add_body_field()
but that doesn't reply to a hook call, it's called directly and I couldn't yet decide where to do it from in my own code. I still tend to contemplate this route, especially if you tell me this is a wild goose chase, a known limitation that I'm sure to run into and have no chance of solving...