Error when using 'Add More' with Inline Entity Form inside Custom Composite field

Created on 31 December 2024, 10 days ago

Problem/Motivation

When using the Webform Inline Entity Form module, if an Inline Entity Form field is placed inside a Custom Composite field (which allows for the "Add more" functionality to add additional rows), an error occurs when trying to add more rows. The error message is:

InvalidArgumentException: The inline_entity_form #default_value property must be an entity object. in Drupal\inline_entity_form\Element\InlineEntityForm::processEntityForm() (line 99)

This issue arises specifically when clicking the "Add more" button to dynamically add additional rows containing the Inline Entity Form field. The issue does not occur during form submission, but only when trying to add new rows dynamically.

Steps to reproduce

  1. Install and Enable Modules:
    • Install and enable the Webform and Webform Inline Entity Form modules.
  2. Create a Webform:
    • Go to Structure > Webforms and create a new Webform.
  3. Add a Custom Composite Field:
    • Add a Custom Composite field to the Webform.
    • In the Custom Composite field, add multiple sub-fields (e.g., text fields, select fields, etc.) that should appear as part of a single row.
    • Enable the "Add more" functionality, which allows users to add additional rows containing the same set of fields.
  4. Add an Inline Entity Form Field Inside the Custom Composite Field:
    • Within the Custom Composite field, add an Inline Entity Form field.
    • Configure the Inline Entity Form to create or update a custom entity (e.g., a custom content type or another entity).
    • Set the #default_value property for the Inline Entity Form field to a valid entity object (either an existing entity or a new one to be created).
  5. Use the "Add More" Option:
    • On the Webform, use the "Add more" button to add another row with the same fields, including an additional Inline Entity Form.
    • When the "Add more" button is clicked, the following error occurs:
      InvalidArgumentException: The inline_entity_form #default_value property must be an entity object. in Drupal\inline_entity_form\Element\InlineEntityForm::processEntityForm() (line 99)
                  

Proposed resolution

The issue likely stems from the Inline Entity Form not correctly handling the #default_value property when placed inside a Custom Composite field with the "Add more" functionality.

  • Fix: Update the handling of the Inline Entity Form field within composite fields, ensuring that the #default_value is recognized as a valid entity object when a new row is added dynamically using the "Add more" feature.
  • Alternative: Investigate how Custom Composite fields and Inline Entity Form interact with each other, and ensure that Inline Entity Form fields are correctly initialized when new rows are added.

Remaining tasks

  • Investigate how the #default_value is being passed and processed when new rows are dynamically added.
  • Determine if the issue is with how composite fields handle dynamic form elements or if it is a problem with the Inline Entity Form's integration with them.
  • Test a solution that ensures the Inline Entity Form handles the dynamic nature of composite fields when rows are added.

User interface changes

No UI changes are expected, but users will benefit from the ability to dynamically add new rows containing the Inline Entity Form field without encountering errors.

API changes

There are no expected API changes, but there may be improvements in how the #default_value property is handled for Inline Entity Form fields inside composite fields.

Data model changes

No data model changes are anticipated. However, if a solution involves changes to how entities are initialized or passed to Inline Entity Form fields, this may impact the entity data structure when using the Add more functionality.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇮🇳India DhruvR

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024