Not sure what to do about this one.

Problem/Motivation

Any block that contains a form breaks the layout_builder layout configuration interface.

Steps to Reproduce

There are lots of ways to reproduce this I think, the steps below are how I came across it.

  1. Install views_block_filter_block - this allows block view displays to have exposed filters.
  2. Configure a view block with an exposed filter
  3. Add the view block to an entity layout
  4. Click 'Save Layout'

The page will refresh and still read "You have unsaved changes".

Why is this happening?

The block preview renders the exposed filters form with the view. This nests one form element inside another. Chrome (and presumably other browsers) then fixes this html so that the layout builder form starts where it should, but ends at the views exposed filters. This excludes the form_id, form_build_id and form_token hidden elements from the form submission so drupal never executes the submit handlers.

Possible Solution

Quick
Set the weight on the 'layout_builder' element really high so that the hidden inputs are all rendered before the layout. This would ensure that they always get submitted with the 'Save Layout' form. This seems like a hacky work around to me though, we would still be rendering invalid html.

Better
Separate the rendered layout from the form. All of the settings are stored in the tempstore rather than read from the form submission, so there is no reason to have the layout preview inside the

tags at all. This could be achieved with a custom controller.

Comments

rlmumford created an issue. See original summary.

tim.plunkett’s picture

Closing as a duplicate