Flattening webform elements with getElementsDecodedAndFlattened() breaks the layout and hierarchy.

Created on 25 November 2024, 9 days ago

Problem/Motivation

The current implementation of the webform_invitation module uses the getElementsDecodedAndFlattened() method to retrieve webform elements. This method flattens the structure, causing parent-child relationships between elements to be lost. When the modified elements are saved back to the webform using setElements(), the layout and hierarchy of the webform break.

This issue impacts webforms with nested structures, such as fields within fieldsets or other grouping elements, resulting in:

  • Improper rendering of the form.
  • Loss of logical grouping of elements.

Maintaining the original hierarchy is critical for proper webform functionality and layout.

Steps to reproduce

  1. Enable the webform_invitation module on a Drupal site.
  2. Create or edit a webform that contains nested elements (e.g., fields within a fieldset).
  3. Enable invitations for the webform.
  4. Observe the webform layout after saving.

The hierarchy and parent-child relationships are broken, and all elements appear at the top level.

Proposed resolution

Replace the use of getElementsDecodedAndFlattened() with getElementsDecoded() in the code where elements are manipulated.

Rationale: getElementsDecoded() preserves the hierarchical structure of elements, ensuring that modifications do not break the layout or relationships.

Remaining tasks

  1. Refactor the relevant code in the webform_invitation module to use getElementsDecoded().
  2. Test the changes with webforms containing:
    • Nested structures (e.g., fieldsets, details).
    • Non-nested structures (to ensure backward compatibility).
  3. Verify that the new element is added at the top without disrupting the existing layout.
πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΎUruguay santiagotrindade

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024