Form blocks rendered inside layout builder break save

Created on 2 April 2019, over 5 years ago
Updated 8 November 2024, 13 days ago

Problem/Motivation

I can no longer save changes to the layout after any kind of form has been added to the layout.

Steps to reproduce:
1. Enable layout builder on a content type, then open layout builder.
2. Add 'Search Form' block to a section
3. Save the layout
4. Re-open the layout builder, and make some change (e.g. reorder blocks)
5. Attempt to save the layout

The page refreshes, but still shows unsaved changes. At this point, it is no longer possible to save the layout until the search form is removed.

Proposed resolution

Since the layout_builder element is not a form element, and all the layout-related values are managed through the temp store, the layout_builder element can be placed outside the form element, preventing nested <form> tags

  1. For the layout_builder render elements in the layout builder defaults and overrides forms, save the list of array parents to a property ('#layout_builder_element_keys') on the top-level $form element.
  2. Override/decorate the controller.entity_form controller service.
  3. If the form render array returned from the original service's getContentResult() method does not have the '#layout_builder_element_keys' property, return the form render array as is.
  4. If the form render array does have have the '#layout_builder_element_keys' property, then use the property to extract the layout builder element from the form render array and move into a separate render array. Return a render array that has the form and the layout builder element array as sibling child elements.

    Remaining tasks

    N/A

    User interface changes

    Layout Builder UI will no longer break when rendering forms

    API changes

    N/A

    Data model changes

    N/A

    Release notes snippet

🐛 Bug report
Status

Fixed

Version

8.9 ⚰️

Component

layout_builder.module

Created by

🇬🇧United Kingdom grahamC Oxford, UK

Live updates comments and jobs are added and updated live.
  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024