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:
ConditionalFieldsHooks::inlineEntityFormEntityFormAlter()addsconditional_fields_form_after_buildto the Inline Entity Form subform.addValidationCallback()then addsformValidate()to that subform's#validate. Drupal only executes form-level#validatecallbacks on the top-level form.- On the outer form,
hasConditionalFields()returns early when its own#conditional_fieldsis empty. Dependencies from the embedded entity are nested inside the subform, so the outer form does not registerformValidate()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
- Install
inline_entity_form. - Create content type IEF Test with two plain text fields,
field_ief_triggerandfield_ief_subtitle. Configure a default value forfield_ief_subtitle. - On Article, add an entity reference field
field_ieftargeting IEF Test, and set its form display widget to Inline entity form - Simple. - At
admin/structure/types/manage/ief_test/conditionals, makefield_ief_subtitledepend onfield_ief_trigger: state Unchanged, condition Value, widget valuetrigger. Enable Reset the target to its default values…. - Add an Article. In the inline form, enter something other than
triggerinfield_ief_trigger, then replace the default value infield_ief_subtitlewith 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. ItscreateHostCondition()currently works around this bug; removing that call reproduces the failure.
Comments
Comment #2
joelpittetPossible related issue #3456407: Conditions don't work when fileds are called trough Inline Entity Reference Form
Comment #3
joelpittetUpdating steps to reproduce