Problem/Motivation

Form alter hooks are not being called for forms included using either the single or multiple inline entity form widgets.

Example scenario:

  • Node A with Entity Reference field to Node B using single/multiple inline entity form widget
  • Implement either hook_form_alter(), hook_form_BASE_FORM_ID_alter() or hook_form_FORM_ID_alter()

The problem is that hook_form_alter(), hook_form_BASE_FORM_ID_alter() or hook_form_FORM_ID_alter() are called for Node A, but they are not called for Node B.

Proposed resolution

Call alter hooks for forms included using the inline entity form widgets.

Remaining tasks

  • Write patch
  • Review
  • Commit

Comments

bojanz’s picture

Status: Active » Closed (won't fix)

The subforms are not built as real forms, hence the default alter hook not firing. This is usually a good thing, because the context of the inline form is sufficiently different that you might not want the same alterations applying to the main form and to the subform.

Use hook_inline_entity_form_entity_form_alter() which is documented in inline_entity_form.api.php

jantoine’s picture

@bojanz,

Thanks for the quick feedback. I had seen that hook but wanted to be sure that not calling form alters was expected behaviour. I was able to quickly implement the hook and pass the $form and $form_state variables to the existing alter hook!