Problem/Motivation

Server-side conditional field handling does not run when the only dependencies are inside an inline_entity_form subform. Dependents are collected during element validation, but ConditionalFieldsFormHelper::formValidate() is never called, so untriggered dependents are not reset and their validation errors are not removed.

Two things combine to cause this:

  1. ConditionalFieldsHooks::inlineEntityFormEntityFormAlter() adds conditional_fields_form_after_build to the Inline Entity Form subform. addValidationCallback() then adds formValidate() to that subform's #validate. Drupal only executes form-level #validate callbacks on the top-level form.
  2. On the outer form, hasConditionalFields() returns early when its own #conditional_fields is empty. Dependencies from the embedded entity are nested inside the subform, so the outer form does not register formValidate() either.

This makes the bug configuration-dependent. If the host content type has any conditional dependency of its own, the outer form registers formValidate() and the Inline Entity Form dependents start working as expected.

Steps to reproduce

  1. Install inline_entity_form.
  2. Create content type IEF Test with two plain text fields, field_ief_trigger and field_ief_subtitle. Configure a default value for field_ief_subtitle.
  3. On Article, add an entity reference field field_ief targeting IEF Test, and set its form display widget to Inline entity form - Simple.
  4. At admin/structure/types/manage/ief_test/conditionals, make field_ief_subtitle depend on field_ief_trigger: state Unchanged, condition Value, widget value trigger. Enable Reset the target to its default values….
  5. Add an Article. In the inline form, enter something other than trigger in field_ief_trigger, then replace the default value in field_ief_subtitle with different text. Save.

Actual: field_ief_subtitle keeps the submitted value.

Expected: field_ief_subtitle resets to its configured default value.

Now add any dependency between two Article fields at admin/structure/types/manage/article/conditionals and repeat the test. The reset works. That difference is the bug.

Proposed resolution

Ensure formValidate() is registered on the top-level form when conditional dependencies are contributed by a nested Inline Entity Form subform.

Remaining tasks

  • Add regression coverage where the Inline Entity Form has dependencies but the host form does not.
  • Adapt ConditionalFieldInlineEntityFormTest. Its createHostCondition() currently works around this bug; removing that call reproduces the failure.

Comments

joelpittet created an issue. See original summary.

joelpittet’s picture

Issue summary: View changes

Updating steps to reproduce