Skip to main content
Bumped by Community user
Bumped by Community user
Added version 8 tag
Link
beltouche
  • 729
  • 5
  • 14
Source Link
beltouche
  • 729
  • 5
  • 14

How to access and change a form's display mode in hook_form_alter() or similar?

Is it possible to access and change a form's display mode in hook_form_alter()? I'd like to use some context to say "use this display mode, not the other one."

My specific use case is selecting a form display mode for a paragraph type nested (in multiple layers) inside one of several node forms. Based on details of the parent layers, I want to control which form display mode is used.

I've looked at hook_field_widget_entity_reference_paragraphs_form_alter() and hook_entity_form_display_alter() as well. While I could, it seems in principle, change the display in that last one, there's no information I could use to make the decision. The widget function doesn't seem to provide anything that looks potentially useful.

I would expect some sort of connection from either the $form or $form_state in hook_form_alter() to the display being used, but can't find one. Either I haven't dug down the right rabbit hole, or that connection doesn't exist there, and I need to look at some other processing step, but don't know which.