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

CommentFileSizeAuthor
#197 drupal-layout_builder_unable_to_save-3045171-197.patch4.73 KBkavya n n
#192 layout-builder-save-issue-when-form-inside-3045171-192.patch1.02 KBoleh.tarasiuk
#149 3045171-interdiff-no-decorator.txt3.56 KBsam152
#140 interdiff_136-140.txt3.42 KBgodotislate
#140 layout-builder-save-issue-3045171-140.patch20.79 KBgodotislate
#136 layout-builder-save-issue-3045171-136.patch20.74 KBgodotislate
#136 interdiff_135-136.txt5.57 KBgodotislate
#135 interdiff_134-135.txt1.75 KBgodotislate
#135 layout-builder-save-issue-3045171-135.patch19.89 KBgodotislate
#134 interdiff_132-134.txt5.08 KBgodotislate
#134 layout-builder-save-issue-3045171-134.patch20.17 KBgodotislate
#132 layout-builder-save-issue-3045171-132-test-only.patch14.29 KBgodotislate
#132 interdiff_124-132.txt7.41 KBgodotislate
#131 3045171-131.patch7.68 KBrlmumford
#131 interdiff.txt1.03 KBrlmumford
#129 3045171-129.patch7.68 KBrlmumford
#129 interdiff.txt4.97 KBrlmumford
#127 3045171-126.patch6.9 KBrlmumford
#124 layout-builder-save-issue-3045171-123-test-only.patch12.43 KBgodotislate
#120 interdiff-3045171-116-120.txt1.38 KBMadhura BK
#120 layout-builder-save-issue-3045171-120.patch4.73 KBMadhura BK
#116 interdiff.txt999 bytesshimpy
#116 3045171_116.patch5.81 KBshimpy
#107 drupal-layout_builder_unable_to_save-3045171-105.patch4.73 KBrensingh99
#107 interdiff.txt155 bytesrensingh99
#107 Screenshot_4.png11.89 KBrensingh99
#107 error.png20.01 KBrensingh99
#103 drupal-layout_builder_unable_to_save-3045171-103.patch4.73 KBbkosborne
#102 drupal-layout_builder_unable_to_save-3045171-102.patch0 bytesbkosborne
#102 interdiff_99_102.txt8.25 KBbkosborne
#99 interdiff_77_79.txt1.27 KBa3hill
#99 drupal-layout_builder_unable_to_save-3045171-99.patch4 KBa3hill
#85 Img.png51.78 KBrenatog
#79 3045171-79.patch5.3 KBrlmumford
#77 drupal-layout_builder_unable_to_save-3045171-77.patch3.93 KBcoderbrandon
#71 interdiff-66_71.txt4.41 KBxaqrox
#71 3045171-71.patch19.72 KBxaqrox
#67 3045171-66.patch19.65 KBbnjmnm
#67 interdiff_44-66.txt11.45 KBbnjmnm
#63 3045171-nestedform-63.patch1.8 KBmpaler
#58 3045171-nestedform-58.patch1.8 KBmpaler
#44 3045171--44.patch11.26 KBbnjmnm
#44 interdiff__41-44.txt8.55 KBbnjmnm
#44 3045171-44-with-3025231-67.patch56.28 KBbnjmnm
#44 3045171-44-TESTONLY-PLUS_3025231-67.patch54.64 KBbnjmnm
#44 3045171-44-TEST-ONLY.patch9.02 KBbnjmnm
#41 3045171-41-different-approach.patch3.16 KBbnjmnm
#36 interdiff-34-36.txt9.61 KBccasals
#36 3045171-nestedform-36.patch12.44 KBccasals
#34 interdiff.txt1.58 KBphjou
#34 3045171-nestedform-34.patch3.9 KBphjou
#32 interdiff-28-32.txt221 bytesccasals
#32 3045171-nestedform-32.patch3.84 KBccasals
#29 interdiff-25-28.txt3.49 KBccasals
#29 3045171-nestedform-28.patch3.84 KBccasals
#25 3045171-nestedform-25.patch1.8 KBccasals
#25 interdiff-14-25.txt340 bytesccasals
#21 interdiff-19-21.txt1.49 KBrlmumford
#21 3045171-21.patch5.24 KBrlmumford
#19 3045171-19.patch4.69 KBrlmumford
#14 3045171-nestedform-14.patch1.77 KBgnuget
#13 laybuilder-edit.png11.03 MBoheller
#10 3045171-nestedform-10--fail.patch1.56 KBjohnwebdev
#9 Screen Shot 2019-04-15 at 22.23.32.png94.02 KBjohnwebdev
#8 3045171-nestedform-8.patch2.53 KBgodotislate
#3 3045171-nestedform-3.patch1.78 KBtim.plunkett

Comments

grahamC created an issue. See original summary.

grahamc’s picture

Looking at the form data posted by the browser, this would normally include form_build_id,form_id and form_token fields, but in this case these are missing...

tim.plunkett’s picture

Status: Active » Needs review
Issue tags: +Blocks-Layouts, +Needs tests
StatusFileSize
new1.78 KB

Oh no, that's not good.
Must have broken in #3004536: Move the Layout Builder UI into an entity form for better integration with other content authoring modules and core features.

First step to fixing this is an automated test, tagging for that.
I'd suggest using the User Login form, so we don't have to mess with search.module in our test.

Not sure if it's truly fixable, but in the meantime, here's a workaround to always show a placeholder when a block contains a form.

Status: Needs review » Needs work

The last submitted patch, 3: 3045171-nestedform-3.patch, failed testing. View results

tim.plunkett’s picture

grahamc’s picture

The workaround from #3 seems a reasonable compromise, but unfortunately doesn't cover blocks from the Webform module, where I'm hitting the same problem.

(These have a $content['#type'] of 'webform', and no child elements)

For now I'll be extending the workaround to handle webforms too, but, obviously core shouldn't be name-checking RenderElements from contrib modules, so there ought to be a better solution...

Should Webform have to detect that it's running inside layout builder and avoid outputting forms?

godotislate’s picture

StatusFileSize
new2.53 KB

I had to deal with some blocks containing content with form tags added directly to templates, so my workaround was so swap all rendered <form> tags with <div> tags. I don't have tests written for this, as I'm not sure it's a great way to deal with the issue.

johnwebdev’s picture

StatusFileSize
new94.02 KB

Super tricky!

This expands (and simplifies the approach from #8) but I'm not sure if it's the right one. Not submitting as patch yet, until we validate if we should actually do it this way.

So basically something like:

      if ($event->inPreview()) {
        /** @var \Drupal\Core\Render\RendererInterface $renderer */
        $renderer = \Drupal::service('renderer');

        $build_copy = $build;

        $markup = $renderer->render($build_copy);

        $html = Html::load((string) $markup);

        if ($html->getElementsByTagName('form')->count() > 0) {
          $build['content'] = [];
          $is_content_empty = TRUE;
        }
      }

would produce:

johnwebdev’s picture

StatusFileSize
new1.56 KB

This is a failing test. (It passes with code in patch #9 and probably #3) But this wouldn't fail for #7, so we should probably expand this and add a block plugin in a test module that renders a form and probably move this to its own test class with that scenario covered as well.

Not setting to NR.

tim.plunkett’s picture

jwilson3’s picture

From a technical perspective, #9 seems to be the safer (albeit nuclear) solution, but from an end-user perspective #8 would be more desirable. It would be useful to see a non-functioning preview of the actual form you want to add to the page, so you can decide if it is the right form or not (etc) without having to go through multiple Save changes /=> View page /=> Edit layout /=> Save Changes /=> View page steps.

So then the question becomes how to effectively show a form without visually disabling the components in the form while also ensuring it doesn't interfere with the outer Layout Builder form. The first part is swapping <form> with <div> like #8 does, but I presume something else would need to be done so that the form elements don't actually submit with the form. Would removing the name="" attributes from all the form elements work?

oheller’s picture

StatusFileSize
new11.03 MB

I've applied patch-8 and when I go to edit the layout I get the following errors:
I'm using Drupal core: 8.7.1.

Fatal error: Maximum function nesting level of '256' reached, aborting! in docroot/core/lib/Drupal/Core/TypedData/DataReferenceDefinition.php on line 48.

Fatal error: Maximum function nesting level of '256' reached, aborting! in Unknown on line 0.

Fatal error: Maximum function nesting level of '256' reached, aborting! in vendor/symfony/http-foundation/Session/Storage/Proxy/SessionHandlerProxy.php on line 65.

Fatal error: Maximum function nesting level of '256' reached, aborting! in /var/www/mndor/docroot/core/includes/bootstrap.inc on line 585.

gnuget’s picture

StatusFileSize
new1.77 KB

I just rerolled #3.

johnwebdev’s picture

yogeshmpawar’s picture

Status: Needs work » Needs review

Setting back to Needs Review & Triggering bots.

Status: Needs review » Needs work

The last submitted patch, 14: 3045171-nestedform-14.patch, failed testing. View results

tim.plunkett’s picture

Priority: Normal » Major
rlmumford’s picture

Status: Needs work » Needs review
StatusFileSize
new4.69 KB

This patch takes a slightly different approach that resolves the issue without having to alter block output.

The patch uses a #pre_render added to the form and a theme hook suggestion to move the layout builder out of the <form></form> tags.

All changes to layouts seem to be made through interactions with the temp-store factory anyway (AFAIK), so nothing from the layout builder element actually needs to be submitted with the form (happy to be corrected on this).

This works a treat for DefaultsEntityForm and OverridesEntityForm out of the box (and doesn't change what users would see at all). If you wanted to display other fields on the OverridesEntityForm then these would always appear above the layout, regardless of weight.

Status: Needs review » Needs work

The last submitted patch, 19: 3045171-19.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rlmumford’s picture

Status: Needs work » Needs review
StatusFileSize
new5.24 KB
new1.49 KB

Fixed code style and test errors.

ccasals’s picture

Manual testing of #21 results in a layout tab with no content in it. (workflow actions are present but none of the content or sections or LB interface renders.)

rlmumford’s picture

@ccasals is that with overrides or defaults?

ccasals’s picture

@rlmumford - with overrides. We have a site with existing content, including form blocks, which recreates this issue. The forms are a user login form, a webform views exposed filter form, and a custom form plugin. This is NOT a clean install of drupal.

ccasals’s picture

StatusFileSize
new340 bytes
new1.8 KB

On further investigation it was the exposed view filter that was causing the issue. Here's an update to #14 that makes it an even bigger hammer. Nested to prevent "undefined index['#type']" errors. That test will still fail, but this at least provides a bandaid for any other sites out there that have content editing blocked by this issue.

Edit for clarity: manual testing of #14 did not resolve the issue. Views form was the culprit.

Status: Needs review » Needs work

The last submitted patch, 25: 3045171-nestedform-25.patch, failed testing. View results

bnjmnm’s picture

In case context is helpful: The test failing in #25 was added in #2973921: Interactive controls inside preview block in the Layout Builder form should be disabled.. This issue disabled interactive elements (including form fields) in Layout Builder preview. The tests included adding a search block to confirm its form elements were disabled.
If the solution to this issue is winds up being the current approach of removing forms entirely, you can address the test failures by removing the parts of LayoutBuilderDisableInteractionsTest that refer to the search block (assuming there is test coverage elsewhere that confirming that forms wont even get rendered in preview).

mpotter’s picture

I ran into this issue when embedding several Views blocks into a Layout. The patch in #25 worked and allowed me to save the layout changes. However, the content editors managing the layout were surprised to see the Placeholders for the Views blocks rather than the content.

Wondering if there is a way to still show the block content but not have it affect the Save action. Or at least show Views that do not contain any exposed filters or forms. In my case, the block causing the problem was a Solr search form. But that was only one of several views on the page. I'd be fine if the search form didn't render but the rest did. As it stands this sort of ruins the WYSIWYG-like Layout builder experience people were excited about. And yet this is definitely a major issue that has broken sites that were working with Layout builder prior to 8.7.

ccasals’s picture

StatusFileSize
new3.84 KB
new3.49 KB

We were still finding forms that could sneak through. Refactoring the approach in #25 to look more like #8/9 by actually checking for
in rendered content.
The failing test still needs to be updated IF this is an acceptable approach (per points made in #27).

mpotter’s picture

Yes, #29 worked better for me. Normal Views blocks are shown, but not the search form. Layout saves. Nice job!

saseedharan’s picture

We were still getting the issue You have unsaved changes On click of Save Layout. I am adding just 2 blocks in the layout a view block and exposed filter block. The version we were using is 8.7.1

Steps to reproduce:
1. Go to any content which uses layout builder.
2. Add any 'view block' to a section.
3. Save the layout. It will be success.
4. Re-open the layout builder.
5. Add any 'Exposed filter block' to the section.
6. Now try to save the layout. You can see You have unsaved changes.

ccasals’s picture

StatusFileSize
new3.84 KB
new221 bytes

Simple update to #29 to work with php 7.1.x sites. "count" is not an available method on https://www.php.net/manual/en/class.domnodelist.php prior to 7.2.

phjou’s picture

I encounter the same bug.

Patch #32 Works for me :)

phjou’s picture

StatusFileSize
new3.9 KB
new1.58 KB

Ok I just updated the patch to use the interface in the dependency injection instead of the class directly.

bnjmnm’s picture

I discovered a less disruptive solution for the search form while working on #3025231: Concurrent editing of layouts is very confusing.

In \Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray::onBuildRender() just after $content = $block->build(); I added

if (isset($content['#type']) && $content['#type'] === 'form' && $event->inPreview()) {
        unset($content['#theme_wrappers']);
      }

When #theme_wrappers was present, the Layout Builder form's CSRF token was being rendered outside of the form.

This addresses the inability to save without any UI changes.

It's possible that this only works in combination with other changes made in the issue - I have not tested that. If just the change in onBuildRender() does not fix the issue for search form, check #3025231, which should soon have a patch with that + the other changes that fix the save issue.

ccasals’s picture

Updates for unit tests, building on update in #34. The functional js test (LayoutBuilderDisableInteractionsTest) will still fail

Also opened a new issue: https://www.drupal.org/project/drupal/issues/3060656
This is for a longer term better approach that might still allow rendering of forms, if that's possible.

ccasals’s picture

Status: Needs work » Needs review

Triggering the bots to ensure unit tests pass

The last submitted patch, 29: 3045171-nestedform-28.patch, failed testing. View results

The last submitted patch, 34: 3045171-nestedform-34.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 36: 3045171-nestedform-36.patch, failed testing. View results

bnjmnm’s picture

Status: Needs work » Needs review
StatusFileSize
new3.16 KB

This patch is an entirely different approach so there's no interdiff as it's starting from scratch.

With this approach, there is no visible difference with non-views forms, in a render array, it removes the #theme_wrapper key from any item where #type === 'form'

I couldn't do it as cleanly for views blocks with exposed filters since the logic is inside the views executable object. In this case, the views exposed filter form does not render. On the plus side, the rest of the view renders just fine, so it's still a more robust preview than just a label.

sam152’s picture

I'm not quite sure that'll work, since I believe required form elements still add validation messages when saving the layout. It might be worth coming up with a few test forms to use as the baseline and for testing whichever chosen solution we go with.

ccasals’s picture

Would #41 still result in actual nested <form>..<form>..</form>..</form>? It seems like it would, but maybe I am missing the significance of those theme wrappers.

Even if we transform <form> tags to <div>s, this could still break styles that targeted form elements directly which would be hard to solve for and communicate around I would think.

bnjmnm’s picture

Added tests that replicate the steps that cause the problem to happen manually, but the tests won't fail. This is not entirely surprising as there are existing tests that also should have failed as they include adding a block with a form and saving a layout.

Fortunately (albeit confusingly), the changes made in #3025231-67: Concurrent editing of layouts is very confusing -- a test-passing patch -- make it so manual and automated testing are consistent. Most likely this patch made it possible to surface these errors in tests because AJAX rebuilds were changed to target the entire entity form instead of just the Layout Builder render element. Based on this, I've attached the following:

  1. 3045171-44-TEST-ONLY.patch Recreates the steps required to cause the problem reported in this issue. There are iterations with the Search Block, Login Block, and a View with exposed filters. Despite recreating the steps that surface the problem manually, these tests pass but shouldn't.
  2. 3045171-44-TESTONLY-PLUS_3025231-67.patch All the changes in #1 + adds the working patch from #3025231-67: Concurrent editing of layouts is very confusing . (minus one change to BlockComponentRenderArray which was added to address the symptoms reported here). The tests now fail as expected.
  3. 3045171-44-with-3025231-67.patchEverything in #2 + the fixes I added to BlockComponentRenderArray in #41 The tests should pass as expected (running the test again, there was an unrelated fail due to a known media library issue, but the Layout Builder tests pass as expected)
  4. 3045171-44.patch The tests from #1 + the fixes I added to BlockComponentRenderArray in #41. Tests pass because these tests pass without the patch from 3025231...

The last submitted patch, 44: 3045171-44-with-3025231-67.patch, failed testing. View results

The last submitted patch, 44: 3045171-44-TESTONLY-PLUS_3025231-67.patch, failed testing. View results

bnjmnm’s picture

Status: Needs review » Postponed
Related issues: +#3025231: Concurrent editing of layouts is very confusing

Talked with @tim.plunkett about #44 and we concluded this should be postponed until #3025231: Concurrent editing of layouts is very confusing is completed, as it isn't possible to write test coverage for this issue without it.

In the meantime 3045171--44.patch from #44 should take care of the issue with minimal changes to the Layout Builder UI.

scottsawyer’s picture

For what it's worth 3045171--44.patch works great for Drupal 8.7.3.

godotislate’s picture

I had originally used a workaround similar to #44 in our project, but realized it didn't solve the issue for webforms as mentioned in #7, or other render elements that have <form> tags in the template.

I think behavior I have observed is that such blocks might save in LB the first time they are added to the layout, (though possibly not if the form contains any required fields). However, saving after going back and re-editing the layout subsequently will fail.

scottsawyer’s picture

Good lord, I just ran into a combination that #44 doesn't address. I have a view with an exposed for in QuickTabs. Those form tags are still present in LayoutBuilder. Not sure how to proceed. I guess I could temporarily disable the exposed filters, update the layout, then re-enable. Let's how we can get #3025231 in quickly :)

mpaler’s picture

Dang. Almost feel like this bug is borderline critical. In my case, if I want to edit a layout with a form(s), I need to remove the forms, make the edits, save -- then re-edit and place the forms again.

tim.plunkett’s picture

@mpaler is the most recent patch solving your issue

mpaler’s picture

@tim.plunkett -- sadly it's not. I'm on D8.7.3 -- and I have https://www.drupal.org/files/issues/2019-06-19/3045171--44.patch applied. Just tested again. I my case I have a straight up content block with a
inside the block. Trying to save and it never saves, even if i toggle "Show content preview". Removing the block saving a few times (with and without "Show content preview") and the node saves.

FWIW, I also have the following patch applied:

https://www.drupal.org/files/issues/2019-06-18/3053906-11-default-region...

Thanks for all you guys do!

tudxndvn’s picture

hi all, do you any thing new today?

bnjmnm’s picture

@mpaler two things would help narrow down why the current fixes are not working for you

  • It's possible that 3045171-44-with-3025231-67.patch may work for you where the main patch from #44 did not. If you're able to check with that patch, please share the outcome here. To be on the safe side, manually clear caches after applying the patch.
  • If you're not able to test with that other patch, or it does not address you issue, we could use more details about the save-breaking form content in your block so we can reproduce the problem locally and expand the fix to address your use case.
mpaler’s picture

@bnjmnm,

3045171-44-with-3025231-67.patch is not applying on 8.7.3 -- even with no other core patches.

Going back to 3045171--44.patch and going to work around for now.

Here's my custom block code in entirety, minus the complete post destination:

<div class="row">
<div class="col-xs-12 col-sm-6 sign-up">Sign up for our monthly newsletter</div>

<div class="col-xs-12 col-sm-6 col-lg-5 form">
<form action="https://go.pardot.com" method="post"><input class="email-address" id="vresp-email" name="email_address" placeholder="Enter your email address here" size="15" type="text" value="" /><input class="btn btn-primary" id="vresp-submit" name="op" type="submit" value="Sign up" />&nbsp;</form>
</div>

<div class="hidden-xs hidden-xs hidden-sm hidden-md col-lg-1 spacer">&nbsp;</div>
</div>

Thank you.

gnuget’s picture

I just want to mention that I'm still using #3 with the modifications mentioned by #7 (I was testing it with a web form) with great results.

It removes the form and displays a text which is not ideal but it lets the UI usable for the user while this is fixed properly :-)

mpaler’s picture

StatusFileSize
new1.8 KB

@gnuget -- thanks for the tip. Went that route as we are on a tight timeline. Attached is a re-roll with the webform conditional in case it helps anyone else in a similar crunch.

scottsawyer’s picture

Any thoughts on how to deal with more deeply nested forms, such as with QuickTabs with Views blocks containing exposed filters? I haven't tested against Block Tabs or related modules, but I am wondering is this patch would address such cases.

tim.plunkett’s picture

@ccasals had an approach earlier that rendered the HTML and parsed the DOM. I think that's the only bulletproof solution that would also address hand-written forms like the one in #56
That's been split out to #3060656: Explore a better solution for nested forms in Layout Builder

gnuget’s picture

Hi, @scottsawyer.

I think #58 should work for your case as well.

the containsForm is recursive and it will iterate in all the render array.

If somehow the form is already rendered you could try #36 instead which render first the markup and after that check for the form tag.

scottsawyer’s picture

@gnuget Could not apply #58 to 8.7.3. I have a few other core patches installed, I am going to see if they touch any of the same files.

mpaler’s picture

StatusFileSize
new1.8 KB

@scottsawyer -- that was my bad. Please try this one.

scottsawyer’s picture

Ok, that patch applied, thanks for jumping on it.

However, I still get a form tag in my QuickTabs block in layout builder when the QuickTab contains a views block with an exposed form, and still unable to save the layout with the QuickTabs block.

gnuget’s picture

#36 is the way to go then :-)

I even think that #36 should be committed and any different/better solution should be explored on #3060656: Explore a better solution for nested forms in Layout Builder

scottsawyer’s picture

With #36 I am able to save a layout with QuickTabs. Thanks everyone for your efforts.

bnjmnm’s picture

StatusFileSize
new11.45 KB
new19.65 KB

This builds off of the approach in #36, but instead of hiding the blocks entirely, it replaces all occurrences of <form> with <div>. This preserves the UI.

Tests were also expanded to cover the hard-coded form use case reported in #53

bkosborne’s picture

If you're going to use a regex to perform the replacements, then I suggest not loading into a dom object at all to verify if a form tag exists. I would just use a regex to test if the form element exists as well. Regex is not super reliable for HTML detection and manipulation BTW, since it can take so many different formats. Like < form>... </ form >.

tim.plunkett’s picture

We can be reasonably sure that any <form> tags generated by Drupal will be found here.
Any custom code with malformed HTML isn't really something we can be responsible for...

scottsawyer’s picture

I agree that parsing form tags is hazardous, but it should be rare to have irregular, though not illegal form tags, so unless a better approach is presented, I think this is a 99% solution.

xaqrox’s picture

StatusFileSize
new19.72 KB
new4.41 KB

Here's a patch using DOM shenanigans to convert the form. Also removed detokenizeNestedForms() since it did not appear to be in use any longer.

philosurfer’s picture

#66 & #71 is not working when we have a block type that inserts a media field (uses media browser in modal).

philosurfer’s picture

Noting: The patch in #3042190: Creating a block that uses Ajax adds multiple blocks solves the problem for me when we have block types that have media fields.

rlmumford’s picture

@tim.plunkett (#60) in #21 theres a patch that takes the rendered layout builder out of the form. There was a bug with the overrides, but that approach seems to solve all of the above issues for any form, and renders a realistic preview of the form. Is that not ideal?

bkosborne’s picture

philosurfer, can you provide steps to reproduce?

I applied patch from #66. In layout builder, I can add a views block that has exposed form and save just fine. I can also add a custom text block that has a media reference field on it and have no problem selecting a media item from the media browser (both core's media library widget and the entity browser contrib module widget).

bkosborne’s picture

The current approaches perform the modifications in \Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray but this is not correct and is particularly problematic for the approach in started in #67. This approach performs early rendering of the section render array, and as such prevents other subscribers to the event LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY from acting on the render data. So this breaks contrib (like the Layout Builder Styles module).

Instead, the early rendering and form replacement could be done in SectionComponent::toRenderArray(), after all event subscribers have finished.

But even then, it seems dangerous to do this early rendering, since layout templates may want to modify the render data and will no longer be able to.

I wonder - is a pure JavaScript solution a possibility? Why can't we swap the <form> tag with a <div> using JS?

coderbrandon’s picture

I've rerolled/downrolled the patch from #71 (without tests) so that it can apply to 8.7.1, if it helps anyone else.

chs’s picture

Confirmed in 8.7.5 version build with webform version 5.1.0 build, not available any save both - multilingual and single language,
any possibility to roll patch with backport to previous version?

regards,
Mike

rlmumford’s picture

StatusFileSize
new5.3 KB

Re-roll of patch in #21.

renatog’s picture

#77 works good on 8.7.5 using Webform w/ Layout Builder

ccasals’s picture

Hi all,

This came up recently in conversation so I figured I would clarify here: there are multiple approaches to patching this problem in this issue thread! If you are just looking to patch your site, please patch carefully.

Moving latest to oldest:

Patch thread ending in #79 (started from #21): this approach take the entire layout builder form out of rendering, then re-adds it using a preprocess hook. Has not been tested by the community yet.

Patch thread ending in #77 (builds on #71, #66, #44, #41): this approach renders each block before placing it in the form and if it finds <form> elements it converts them to divs. It will work on any block with a form in it (no matter how deeply nested). This means that forms will probably look right, but are mutated html while in the Layout Builder preview. This has been reviewed and tested by the community and bypasses the problem.

Patch thread ending in #63 (builds on 58): this approach looks for content with #type set to 'form'. If it is set to form, it uses the "placeholder for [block name]" functionality to prevent break. This will work for many types of forms, but there are cases where it won't catch nested forms (aka, in a view block with filter). YMMV

Patch thread ending in #36 (builds on 34, 32, 28, 25, 14, 3): this approach renders the block content, looks for a <form> element. If it finds a form in the block, it uses the "placeholder for [block name]" functionality to prevent break. It will work on any block with a form in it (no matter how deeply nested). This has been reviewed and tested by the community and bypasses the problem.

I think at this point, we need to make a decision on which of these approaches is best on balance, and doesn't impact things like accessibility (I have concerns about malforming semantic forms to look like divs, for instance. I think assistive technologies will probably choke on this.) Every approach has a tradeoff though, so we're going to need to pick which one is least problematic.

batkor’s picture

#77 Works for my. TY

@ccasals Anyway need remove or replace child tags

muaz7731’s picture

+1 for patch #77

kris77’s picture

patch #77 work for me too.

renatog’s picture

Issue summary: View changes
Status: Postponed » Reviewed & tested by the community
StatusFileSize
new51.78 KB

I'm checking and #77 really works well for a lot of members.

I applied the patch, tested and it works here as well.

Updating status for RTBC.

Thank you, guys.

renatog’s picture

Issue summary: View changes
bkosborne’s picture

Status: Reviewed & tested by the community » Needs work

Sorry, but I do not think this is a viable solution. I understand it's working for many people, but the forced early rendering - particularly where it's being done - would prevent some contrib modules from working. See my comment in #76

bnjmnm’s picture

Issue tags: +Needs tests

Re-adding the "Needs tests" tag as the patch that has tests does not appear to be the one people are in favor of.

This issue can't be considered RTBC without a test that replicates the error when unpatched, and has no errors when it is patched

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

rohit tiwari’s picture

Hi,

Applying patch #77 gives me below error,

`ArgumentCountError: Too few arguments to function Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray::__construct(), 1 passed in /var/www/globalcms/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php on line 269 and exactly 2 expected in Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray->__construct() (line 52 of core/modules/layout_builder/src/EventSubscriber/BlockComponentRenderArray.php).`

In our case we are following below steps,

1) We are adding embed form in block.
2) Add the block through layout builder.
3) Able to save the layout.
4) Edit and make any other change and hit save.
5) Unable to save with message `You have unsaved changes`

murz’s picture

@Rohit Tiwari, clearing Drupal cache after applying patch should fix this error.

gerzenstl’s picture

Patch submitted in #79 works well.

I'm using Drupal 8.7.8.

mirom’s picture

@bkosborne none of the approaches from #81 is working for your usecase? #63 seems to be doing the same thing as you describe.

bkosborne’s picture

Hi mirom, my concerns with the approach taken in #77 is outlined in my comment #76. To recap, my issue is that it forces early rendering of the block component before other event subscribers have a chance to alter the render data. This early rendering is performed even if there is no form present in the data.

Contrib that has event subscribers to this block component render event will not have a chance to act on the render data in a meaningful way. For example, the Layout Builder Styles module subscribes to this same event to add CSS classes and template hints to the block. That cannot happen now because the render data has been converted to just #markup with HTML already rendered.

The solution is to do this form replacement in a different area, after the event subscribers have all run.

tim.plunkett’s picture

What about an additional event subscriber that is set with -1000 priority that performs this rendering?

bkosborne’s picture

Can't it just go in SectionComponent::toRenderArray() after all the subscribers are done?

tim.plunkett’s picture

A couple reasons.

  1. I like how relatively clean the method is right now
  2. Adding this by an alterable mechanism allows a custom module to prevent this from running or replace the functionality if needed
  3. Similarly, if needed, a custom module could run *after* this code
bkosborne’s picture

Ok, that makes sense.

I suggest also that the code be modified so that it doesn't perform the early rendering if there is no form found. Right now it's updating the render data by reference. I think it should clone the render data first, and then if a form is found replace the original. That reduces the side effects this may have.

a3hill’s picture

Building upon #77 so items that don't have forms, don't render the content as part of this process and therefore skipping theme preprocessing and templates. In my case, after using patch #77 it fixed the save issue as advertised but disrupted the display of existing themed blocks.

batkor’s picture

#99 Works for my.
Thank guys

johanf’s picture

#77 works fine and #99 works fine too . Thanks

But still a problem ... The form has to be the only block in the section.

If i add the form and a view in the same section i get this 'you have unsaved changes' again

bkosborne’s picture

Status: Needs work » Needs review
StatusFileSize
new8.25 KB
new0 bytes

Here's the same code as #99, but it's moved to a separate event subscriber with a very low priority. This resolves my original concern.

I cannot reproduce the problem from #101. I added several blocks to the section, including several form blocks, and I was able to save the layout. Can you provide more detailed steps to reproduce?

bkosborne’s picture

StatusFileSize
new4.73 KB

Empty file uploaded by accident... Those Gitlab integrations can't come soon enough...

cameron prince’s picture

I was seeing the same as #101, but switching to the new patch in #103 allowed me to save the node. In my case, I was embedding two product entities via the WYSIWYG in two custom blocks added in the same section. The products render inside an add to cart form.

shimpy’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new37.39 KB
new21.42 KB

I have tested patch #103. It works for me. I have added the layout builder in one of the content type and tried managing the content layout. I added search form block or any form entity or node block , it is saving the layout but if I make changes in the block it is showing me unsaved changes tag even after clicking on save layout.
But later i applied the patch #103 it is save the layout without showing the unsaved changes tag.

before patch

after patch

sam152’s picture

Status: Reviewed & tested by the community » Needs review

Hi @shimpy, this issue still has the "needs tests" tag, so it should be marked as "Needs review" or "Needs work" until those are done.

rensingh99’s picture

StatusFileSize
new20.01 KB
new11.89 KB
new155 bytes
new4.73 KB

Hi,

I have checked the patch and it worked as design.

Below are my updates.

1). I have enabled the layout builder for the "basic page" content type.
2). I have added a search form using a layout builder. After that, I was not able to save the layout for a basic page.

3). I was able to save the layout after applying the patch.

4). Also, I have added a view in the same section below the search form and it saved successfully.

There was one error as per the Drupal coding standard. I have fixed it and uploaded the patch with interdiff.

Thanks,
Ren

The last submitted patch, 79: 3045171-79.patch, failed testing. View results

The last submitted patch, 99: drupal-layout_builder_unable_to_save-3045171-99.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kualee’s picture

Status: Needs review » Reviewed & tested by the community

I have tested the patch provided in #107. It applied cleanly and worked as expected.
Here is my test usecase:
- Patch tested on a fresh install of Drupal 8.9 with webform module enabled.
- I conducted testing on basic page content type, adding a few different form elements (either one form at a time or in a few different combination)

  • Webform block
  • Search block
  • Comment block
  • A views block with exposed filter

The patch worked as designed in all different combination of content.
Cheers

sam152’s picture

Status: Reviewed & tested by the community » Needs work

@kualee, unfortunately the patch still needs tests. NW for those.

kualee’s picture

@Sam152 ah sorry I have just re-read your comment in #106. Would you be able to provide some guideline/point me to the direction to work on the automated test? Really keen to get this issue RTBC but I have never contributed anything so not sure where to start. Thanks!

jwilson3’s picture

Hi @kualee,

The documentation to get started on writing tests for core issues is here

https://www.drupal.org/contributor-tasks/write-tests

Without looking too deeply into it, I'd suggest scouring the Drupal 8.9 source code for examples of tests that relate to Layout Builder and possibly tests that relate to event subscribers to get an idea of how tests are being written elsewhere in core.

damontgomery’s picture

#71 has tests if you want a starting point for adding one to #103.

And, thanks for the work everyone.

aangel’s picture

#105 worked for me, thank you everyone.

Spotted a spelling error. $orginal_content should be $original_content.

shimpy’s picture

Status: Needs work » Needs review
StatusFileSize
new5.81 KB
new999 bytes

#107 worked for me. I have corrected the spelling as per #115. Please Review.

cobenash’s picture

#116 worked for me.

Thanks.

tim.plunkett’s picture

Issue summary: View changes
Status: Needs review » Needs work
  1. index 76faef1..80ad9fa 100644
    --- a/core/modules/automated_cron/automated_cron.module
    
    --- a/core/modules/automated_cron/automated_cron.module
    +++ b/core/modules/automated_cron/automated_cron.module
    

    Please remove these unrelated changes.

  2. +++ b/core/modules/layout_builder/src/EventSubscriber/BlockComponentPreviewFormReplace.php
    @@ -0,0 +1,108 @@
    +class BlockComponentPreviewFormReplace implements EventSubscriberInterface {
    ...
    +   * Creates a BlockComponentRenderArray object.
    

    Wrong docblock

  3. +++ b/core/modules/layout_builder/src/EventSubscriber/BlockComponentPreviewFormReplace.php
    @@ -0,0 +1,108 @@
    +   * Change forms to divs if in layout builder's preview mode.
    

    Changes

  4. +++ b/core/modules/layout_builder/src/EventSubscriber/BlockComponentPreviewFormReplace.php
    @@ -0,0 +1,108 @@
    +   * Convert form tags to div when displayed in the Layout Builder UI form.
    

    Converts

I think this also needs an empty post_update hook to allow the new service to be discovered after updating. See layout_builder.post_update.php for examples.

Finally, this still needs tests

Madhura BK’s picture

Assigned: Unassigned » Madhura BK
Madhura BK’s picture

Assigned: Madhura BK » Unassigned
StatusFileSize
new4.73 KB
new1.38 KB

Have implemented changes suggested in #118.

meenakshig’s picture

Status: Needs work » Needs review
tim.plunkett’s picture

Status: Needs review » Needs work

Changes in #120 are fine, but this still needs tests.

kris77’s picture

Patch in #120 works fine for me.

godotislate’s picture

Here is a failing test. 3 different types of blocks are added to both default and overrides layouts:

  • Block containing form api form
  • Block containing inline template which renders a form tag
  • Views block with exposed form

I think these three should provide comprehensive (if not redundant) coverage of blocks containing forms.

It seems that the initial adding of the blocks and saving may succeed, it's just after subsequent editing of the layout with the blocks already in place, it's not possible to save (or discard or revert).

pavel ruban’s picture

deleted*

rlmumford’s picture

I still think the approach outlined in #120 is misguided. It changes the POST data submitted when someone clicks the save button. If there are buttons in the form blocks, clicking them will have the effect of submitting the form.

For example, if any of the forms in the blocks contain a button with the name "Discard Changes", clicking it accidentally or otherwise will result in the layout changes being discarded.

Any form input in the block forms will still be submitted when the layout form is submitted - this just seems wrong. I'm guessing that means that a form_build_id will be submitted for every form displayed in the layout.

Taking the layout out of the form entirely is a better way to go, as it ensures that only the expected data is being submitted when you click "Save Layout" and "Discard Changes". It also stops any submit buttons in the layout blocks having any effect on the layout form. This is the process outlined in #79 and #21.

rlmumford’s picture

Status: Needs work » Needs review
StatusFileSize
new6.9 KB

Reroll of #79 with a test. The test uses the user login form, but i don't know if that will render because the user will be logged in. The search form might be a better fit.

Status: Needs review » Needs work

The last submitted patch, 127: 3045171-126.patch, failed testing. View results

rlmumford’s picture

Status: Needs work » Needs review
StatusFileSize
new4.97 KB
new7.68 KB

Moved the pre render callback into a class for security.

Status: Needs review » Needs work

The last submitted patch, 129: 3045171-129.patch, failed testing. View results

rlmumford’s picture

Status: Needs work » Needs review
StatusFileSize
new1.03 KB
new7.68 KB
godotislate’s picture

I like the idea in #131 of rendering the layout builder element outside the form. I have an alternate approach to do that by decorating the entity form controller service so that a new theme entry isn't required.

But first, a fix/update to the tests in #124

Status: Needs review » Needs work
godotislate’s picture

Patch with fix and tests.

godotislate’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new19.89 KB
new1.75 KB

Realized logic in the controller could be simplified.

godotislate’s picture

Probably better to delay moving the layout builder element outside the form render array at least until after the form is built.

alvarito75’s picture

The patch in #136 works amazingly for me.

kualee’s picture

+1 RTBC
I have tested the patch in #136 and it worked for all of the scenarios that I tested
- Webform
- Comment form
- Views with exposed filter
Tested with either one form at a time or combination of a few
Awesome work @godotislate
And thanks @jwilson3 @damontgomery for the suggestion, I ended up never finding the time to get around to do it :(
Maybe someone could review the source code? I only performed all the tests, not reviewing the actual code. I will leave this as needs review for now

tim.plunkett’s picture

Status: Needs review » Needs work

This is soooo close now! Just a couple small things. But I think the approach is inspired, and I'm excited to see it work out so cleanly

  1. +++ b/core/modules/layout_builder/layout_builder.services.yml
    @@ -51,3 +51,10 @@ services:
    +    # Override the entity form controller to handle the entity layout_builder
    +    # operation.
    +    decorates: controller.entity_form
    +    class: Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController
    +    public: false
    

    👏🏻👏🏻👏🏻

  2. +++ b/core/modules/layout_builder/src/Controller/LayoutBuilderHtmlEntityFormController.php
    @@ -0,0 +1,58 @@
    +class LayoutBuilderHtmlEntityFormController {
    +  use DependencySerializationTrait;
    

    Nit: missing a blank line here

  3. +++ b/core/modules/layout_builder/tests/modules/layout_builder_form_block_test/src/Plugin/Block/TestFormApiFormBlock.php
    @@ -0,0 +1,115 @@
    +class TestFormApiFormBlock extends BlockBase implements ContainerFactoryPluginInterface, FormInterface {
    ...
    +   * SearchBannerFormBlock constructor.
    

    Bad copy/paste here

  4. +++ b/core/modules/layout_builder/tests/modules/layout_builder_form_block_test/src/Plugin/Block/TestFormApiFormBlock.php
    @@ -0,0 +1,115 @@
    +   * @var \Drupal\Core\Form\FormBuilder
    ...
    +   * @param \Drupal\Core\Form\FormBuilder $form_builder
    ...
    +  public function __construct(array $configuration, $plugin_id, $plugin_definition, FormBuilder $form_builder) {
    

    FormBuilderInterface

  5. +++ b/core/modules/layout_builder/tests/modules/layout_builder_form_block_test/src/Plugin/Block/TestFormApiFormBlock.php
    @@ -0,0 +1,115 @@
    +   *   The plugin_id for the plugin instance.
    

    The plugin ID for the plugin instance.

    (there's another issue about fixing it where you copied it from)

  6. +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderNestedFormUiTest.php
    @@ -0,0 +1,165 @@
    +  protected $defaultTheme = 'classy';
    

    Can this be done with stark instead?

godotislate’s picture

Status: Needs work » Needs review
StatusFileSize
new20.79 KB
new3.42 KB

Thanks for the review! Updated patch per comments.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderNestedFormUiTest.php
@@ -12,7 +12,7 @@
-   * The form block labels used a add block link text.
+   * The form block labels used as text for links to add blocks.

Nice, I didn't even notice this, thanks for fixing.

#140 addresses all my feedback, RTBC

kualee’s picture

+1 RTBC
Might be a bit overkill, but I have just retested all the scenarios I did in my previous test with patch #140 applied.

tim.plunkett’s picture

@kualee in this case, it was overkill because the last set of changes were only to documentation and some tests. But it's good practice and a good habit anyway, and I appreciate your thoroughness! Thanks!

rlmumford’s picture

@godotislate thanks for taking that approach and running with it! Some really good improvements and I'm looking forward to this getting committed!

renatog’s picture

I was using #77, today I tested with #140 and really works well here.

+1 to #RTBC

johnwebdev’s picture

This looks amazing! +1 RTBC.

rhovland’s picture

+1 RTBC Works very well on a layout with several embedded views blocks with 50+ forms inside them

acbramley’s picture

Nice! Patch #140 fixed an issue we were still seeing while using #103 with a custom block that was posting to mailchimp. Thanks!

sam152’s picture

StatusFileSize
new3.56 KB

Confirming this patch also worked great on a site I maintain, was able to delete a lot of custom code that emptied forms out on layout builder pages.

One note on the implementation, you could avoid overriding controller.entity_form by specifying a custom _controller for just the layout builder form route that required this fix.

As I'm writing this, I've realised if the layout builder widget found itself on other entity forms somehow, the fix would then fail to be applied, so not sure it's actually an improvement. +1 RTBC.

godotislate’s picture

Does anyone think it's worth moving layoutBuilderElementGetKeys() to a trait?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 140: layout-builder-save-issue-3045171-140.patch, failed testing. View results

tim.plunkett’s picture

Status: Needs work » Reviewed & tested by the community

Testbot fluke (The "https://packages.drupal.org/8/drupal/provider-2019-3%249934973132b9718f8..." file could not be downloaded)

I don't think the two identical one-liner static methods warrant a trait.

batkor’s picture

Thanks you so much guys!
#140 is working. Drupal 8.8.1

alexpott’s picture

Before committing this it'd be great if someone could update the issue summary to reflect the current solution because it doesn't.

This looks like really nice work and a great test.

godotislate’s picture

Issue summary: View changes
godotislate’s picture

Issue summary: View changes
godotislate’s picture

IS updated.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

@godotislate thank you for the issue summary update.

Committed and pushed 0a16b0f112 to 9.0.x and 87bdfdfc49 to 8.9.x. Thanks!

+++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderNestedFormUiTest.php
@@ -0,0 +1,165 @@
+    $assert_session->assertWaitOnAjaxRequest();
+    $assert_session->linkExists($label);
...
+    $assert_session->assertWaitOnAjaxRequest();
+    $page->pressButton('Add block');
+    $assert_session->assertWaitOnAjaxRequest();
+    $assert_session->pageTextContains($label);

Can we get a follow-up to replace these with:

  • \Drupal\FunctionalJavascriptTests\JSWebAssert::waitForLink
  • \Drupal\FunctionalJavascriptTests\JSWebAssert::waitForButton
  • \Drupal\FunctionalJavascriptTests\JSWebAssert::waitForText
diff --git a/core/modules/layout_builder/tests/modules/layout_builder_form_block_test/src/Plugin/Block/TestFormApiFormBlock.php b/core/modules/layout_builder/tests/modules/layout_builder_form_block_test/src/Plugin/Block/TestFormApiFormBlock.php
old mode 100755
new mode 100644

I fixed the file mode on commit.

  • alexpott committed 0a16b0f on 9.0.x
    Issue #3045171 by godotislate, rlmumford, bnjmnm, ccasals, bkosborne,...

  • alexpott committed 87bdfdf on 8.9.x
    Issue #3045171 by godotislate, rlmumford, bnjmnm, ccasals, bkosborne,...

  • alexpott committed f7a4b4b on 9.0.x
    Issue #3045171 follow-up by alexpott: Form blocks rendered inside layout...

  • alexpott committed b94405a on 8.9.x
    Issue #3045171 follow-up by alexpott: Form blocks rendered inside layout...
alexpott’s picture

+++ b/core/modules/layout_builder/tests/modules/layout_builder_form_block_test/layout_builder_form_block_test.info.yml
@@ -0,0 +1,6 @@
+core: 8.x

This broke the D9 build (obvs and oops) - test modules no longer need to declare a core version. I hotfixed this.

catch’s picture

+++ b/core/modules/layout_builder/layout_builder.post_update.php
@@ -190,6 +190,13 @@ function layout_builder_post_update_update_permissions() {
 
+/**
+ * Clear caches due to addition of service decorator for entity form controller.
+ */
+function layout_builder_post_update_override_entity_form_controller() {
+  // Empty post-update hook.
+}
+

If this is only to rebuild the container, it doesn't need an empty post-update - since the container cache key includes Drupal::VERSION

If it's to clear caches too then we do need it.

rfletcher73’s picture

I am using Drupal 8.8.2, can i install this patch from #140 to my Drupal install? I noticed on the patch page it says it is for 8.9.x branch.

damienmckenna’s picture

Just to mention it, #140 applies cleanly against 8.8.x, is there any chance this could be committed there too? Thank you.

@rfletcher73: Yes, you could use patch #140 against your 8.8.x codebase.

rfletcher73’s picture

Thank you. I am having problem installing it on my local drupal build for testing.

I originally installed Drupal with Composer so i think i should use Composer to install the patch file too.

I've updated my composer.json file by adding this block under extra: {..}

"enable-patching": true,
        "patches": {
            "drupal/layout_builder": {
                "Fix layout builder save issue": "https://www.drupal.org/files/issues/2020-02-04/layout-builder-save-issue-3045171-140.patch"
            }
}

Then from the command prompt, i am running composer install. I am getting response back in the tmerinal, but it is not installing the patch. What am i doing wrong here?

damienmckenna’s picture

@rfletcher73: The composer.json file's "patches" item should refer to the package that the patch is applied to, which is "drupal/core" and not "drupal/layout_builder", e.g.:

            "drupal/core": {
                "1356276 - Allow profiles to provide a base/parent profile and load them in the correct order": "https://www.drupal.org/files/issues/2019-12-02/core-1356276-598-89x.patch",
                "#3045171-140: Forms break Layout Builder saving.": "https://www.drupal.org/files/issues/2020-02-04/layout-builder-save-issue-3045171-140.patch"
            },
rfletcher73’s picture

That is what I had at first, but when i ran composer install, it didnt pull the patch in. So, i guessed Layout Builder being a module needed the module way of updating packages. I guessed wrong. :)

I changed it back to drupal/core. I also updated the package information to match what you have, but I think that doesn't have any effect on it, its just there to describe what the patch does. Is that right?

With those changes, when i ran composer install, it worked!!! My first patch applied to Drupal. Thank you!!!

damienmckenna’s picture

Status: Fixed » Reviewed & tested by the community
Issue tags: +Needs release manager review

Could a release manager please review whether this could be backported to 8.8.x? It affects production sites today (which is how I came across it). Thank you.

tim.plunkett’s picture

Version: 8.9.x-dev » 8.8.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

I think it would need a new patch that combines in the hotfix from #163

damienmckenna’s picture

Status: Patch (to be ported) » Reviewed & tested by the community

The patch still applies cleanly to 8.8.x and (in my personal testing) resolves the problem, moving back to RTBC.

rajab natshah’s picture

Using the 3045171-140.patch with 8.8.x-dev

dimilias’s picture

The patch from #140 also solves our case and our form consists of all sorts of types of fields when the issue was occurring, dependent fields, custom fields, computed fields, inline entity forms, comment fields etc. +1 to RTBC.

thetaPC’s picture

Patch #140 works great with core 8.8.4. Thanks!!!

nguyenphan’s picture

I got this problem when use layout builder and block webforms.
It is good with patch #140 (core 8.8.4).
Thanks a lot.

dubs’s picture

Same for me - #140 works a charm - thank you for everyone's work on this :-)

andrimont’s picture

Thank you @godotislate and all for the patch.
On Drupal 8.8.4, the #140 worked for saving the basic page.

Still I keep having (since Drupal 8.8.3) a symptomn : the webform block doesn't show up on a basic page. I am not sure if it is related.
@nguyen.phan, do you see this issue ?

EDIT : In fact, the webform block is fine. There is no trouble now ;-)
The issue was that the setting Allow each content item to have its layout customized was not set anymore. This went unseen because the layout of the basic page still could be customised.

anybody’s picture

Confirming RTBC for #140 on 8.8.x, thank you all very much!

mizage@gmail.com’s picture

#140 worked me. Thanks!

catch’s picture

Version: 8.8.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Fixed

Discussed this with xjm, and neither of us are very keen on backporting this to 8.8 (new post update, new service etc.), running the patch against 8.8 is of course viable, and it's not too long before 8.9.0 gets a release candidate.

Moving this back to fixed against 8.9.x

jaykandari’s picture

geek-merlin’s picture

Great stuff!

The new LayoutBuilderHtmlEntityFormController does not comply with decoration contract though, causing a regression.

neelaj82’s picture

Hi all,

The #140 patch got applied to our version 8.8.4 but the layout builder is not saving still. We are using an exposed form filter view inside the layout builder. If i remove the view from the page then I can save it.

Update: Cache clear was needed after the patch. working now!!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

xjm’s picture

As per #181.

dave reid’s picture

One thing to note about not backporting to 8.8, is that install profiles using composer-patches have no way to conditionally apply patches to specific older versions of projects, which then requires individual sites to manually add the patches-ignore section. Just something to consider for bug fixes, but I get the hesitation about why not to backport this issue.

chucksimply’s picture

Was this applied to the 8.9 production release a few days ago?

jsibley’s picture

Exactly. Production 8.9

chrisck’s picture

Thank you for the work on this patch. I ran into this issue today with Drupal 9.0.7 trying to display a search filter in layout builder. I see that it was committed to 9.0.x. Does anyone know when this would be pushed to a D9 stable release?

antiphon’s picture

This issue has not been fixed in 9.x. I just encountered it with 9.1.4.

oleh.tarasiuk’s picture

Yes, I have the same on 9.2.0, I think issue should be reopened.

need restore section storage from tempstore to resolve it.

rskleven’s picture

I can confirm this is still an issue in 9.3.3.

larowlan’s picture

@rskleven this was fixed in Drupal 8.
If you've got a similar issue in D9, its a different problem - can you please open a new issue with the details of your scenario?

wunaidage’s picture

encountered this issue on drupal 9.4.5

bnjmnm’s picture

To reinforce what @larowlan said in #194 - commenting that you're having a problem a closed issue is not going to result in anything getting fixed. Two year old issues aren't reopened, especially one that automated test coverage objectively proved to have fixed some issues.

It looks like some people are experiencing additional bugs and if those were reported in a new issue something could actually be done about it. Details on how to reproduce the issue or providing a failing test would be necessary, too. The The steps to reproduce in this specific issue no longer cause an issue. It's certainly possible there's a use case that was not accounted for that could be fixed, but "I'm still getting the problem in (version)" is not enough to go on.

If you're just commenting to vent, vent away. If you're hoping a comment here will result in a fix, it won't. There needs to be a new issue reporting the bug, and there needs to be specific steps on how to reproduce the problem.

kavya n n’s picture

Re-rolling the patch for 10.3.X

jwineichen’s picture

#197 worked for me

davidwhthomas’s picture

Just noting, I had the same issue with a views exposed form inside the layout builder layout.

On save, nothing except "op" was submitted and nothing was saved.

The attached patch in #197 fixed the issue for me too, in Drupal 11.2.x