Ensure Proper Handling of #parents in frontend_editing_form_paragraph_form_alter

Created on 17 July 2024, 5 months ago
Updated 1 August 2024, 5 months ago

Problem/Motivation

The frontend_editing module does not correctly set the #parents property in the frontend_editing_form_paragraph_form_alter function. This leads to a TypeError when the form is processed, specifically when using the Layout Paragraphs behavior.

Steps to reproduce

  • Enable the Frontend Editing and Layout Paragraphs modules.
  • Create a content type with a Paragraphs field that includes Layout Paragraphs behavior.
  • Attempt to edit a paragraph through the frontend editing interface.
  • Notice the error: TypeError: array_merge(): Argument #1 must be of type array, null given in array_merge() (line 122 of modules/contrib/layout_paragraphs/src/Plugin/paragraphs/Behavior/LayoutParagraphsBehavior.php).
  • If #parents is set to an empty array, the form appears but is not usable. Layout options are not saved, and the "Layout Options" fieldset may disappear after changing the layout.

Proposed resolution

Update the frontend_editing_form_paragraph_form_alter function to set a proper value for the #parents property (e.g., '#parents' => array_merge($form['#parents'], ['behavior_plugins', $plugin_id])). This ensures that the form's hierarchical structure is accurately represented, allowing for correct retrieval and processing of nested form values, and preventing the TypeError.

🐛 Bug report
Status

Fixed

Version

1.7

Component

Code

Created by

🇦🇹Austria drupov

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