Closed (fixed)
Project:
Drupal core
Version:
11.x-dev
Component:
layout_builder.module
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
26 Feb 2019 at 22:57 UTC
Updated:
5 Feb 2026 at 19:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
tim.plunkettI should clarify that the issue title and summary assume that #3033686: Saving Layout override will revert other field values to their values when the Layout was started. is committed. Postponing accordingly.
Comment #3
xjmComment #5
bnjmnmAssigning to myself to avoid duplicating work. I have a solution working on my local dev enviroment. There's a few additional things I'd like to do then I'll upload the patch and switch back to unassigned.
Comment #6
bnjmnmWas having difficulty getting the block edit ID in a Functional test so went with FunctionalJavascript but can refactor if that is addressed.
On entity save, check if a layout override exists in the tempstore for the entity. If yes, update the context of the temporary section storage entity context with a copy of the entity being saved (other than it retaining the value of the
layout_builder__layoutfield from the entity in tempstore.Comment #7
tim.plunkettThis is awesome!
I think we should use the Drupal::classResolver pattern and have this logic live in an injectable class
There's a whole dance in
\Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::deriveContextsFromRoute()(including an @todo) that needs to be done for the view mode.Follow-up idea: abstract that out to a public helper method?
I'm not 100% sure about this, but it seems right. The other thing would be to consider other fields added to the page, see
content_moderation_entity_form_display_alter()Comment #9
tim.plunkettThe failures point out that this running even for non-fieldable entities. One easy solution would be checking instanceof FieldableEntityInterface, but that should be enforced by the constraints on the contexts. That's not happening here. I opened #3046216: SectionStorageManager::load() does not evaluate constraints to look into fixing this
Comment #10
bnjmnm@tim.plunkett could you clarify your statement from from #7.3 ?
. Does this mean that that the process added in the patch should make to retain any fields added in the manner of
content_moderation_entity_form_display_alter(), or that newly-added fields to and entity should be added to overrides similar to how they are added to defaults, or something entirely different from either of those?Comment #11
tim.plunkett\Drupal\Core\Entity\ContentEntityForm::getEditedFieldNames()will give you the machine names of all fields that need to be taken care of, including theOverridesSectionStorage::FIELD_NAMEThat's protected, but you should be able to safely borrow the approach.
Comment #12
bnjmnmDone.
- Abstracted to two methods in
LayoutEntityHelperTrait.phpFrom what I can tell, fields added this way never make it into the tempstore, so they're not subject to the conditions that lead to stale values appearing. If I'm overlooking something, a suggestion on how to cover this use case in tests should be all I need to account for it fully.
I adressed this by adding a check for
FieldableEntityInterfacewith a @todo referencing #3046216: SectionStorageManager::load() does not evaluate constraints.Comment #14
tim.plunkettNeeds a reroll, LayoutEntityHelperTrait has changed a lot
Comment #15
dhirendra.mishra commentedPatch from #12 got successfully applied for me..I have uploaded screenshot.Please check..So moving it to needs review status.
Comment #16
tim.plunkettAhh it doesn't apply cleanly to 9.0, but it does to 8.9
No need to attach screenshots of applying the patch, that just confuses the issue (compared with screenshots of functionality in a browser)
Comment #17
nedsbeds commentedHi, I am not sure if I am running in to this issue or a slightly different one.
Reproduction steps I am following are
Create a basic page with layout builder enabled
Save page
Open article/layout page
Add text block and set block body to "original"
Update block
Save layout
Open article /layout page
Edit text block and set block body to "updated"
Article body is "updated"
Edit text block.
block body is still "original"
It sounds similar since stale data is being shown in the layout builder interface, but am not sure if this is a separate issue that needs raising.
Tested in 8.7 & 8.8
Comment #18
nedsbeds commentedJust an update on my previous comment for anyone who lands here, since this is a lot more visible in google.
The issue we were seeing had very similar symptoms to this issue, but was actually caused by https://www.drupal.org/project/layout_builder_st/issues/3067646 symmetric translation module.
The patch in that resolved the issue for us
Comment #19
tim.plunkettNeeds a reroll for 9.1
Comment #20
neslee canil pintoComment #21
neslee canil pintoComment #22
tim.plunkettPer the test failure:
Drupal\Tests\BrowserTestBase::$defaultTheme is requiredon the newly added FieldValuesTestComment #23
neslee canil pintoComment #24
jungleClassy is not recommended to use, see https://www.drupal.org/node/3083055
As FieldValuesTest is a brand new Test added by the patch, I'd suggest changing to another theme and adjusting/rewriting the tests if necessary.
Comment #25
prabha1997 commentedComment #26
neslee canil pintoComment #27
prabha1997 commentedComment #28
prabha1997 commentedComment #29
tim.plunkettFailing tests.
Comment #30
nikitagupta commentedComment #31
nikitagupta commentedFixed failed test cases #27.
Comment #33
nikitagupta commentedPlease ignore #31
Fixed failed test cases #27.
Comment #34
nikitagupta commentedComment #36
tanubansal commentedPatch #33 is working fine on 9.1
Comment #40
r_cheh commentedI reproduced this steps after applying 3035992-31.patch in #33 and it not fixed problem with update layout values.
1. Allow custom layout overrides on articles
2. Create an article with body value "original"
3. Save article
4. Open article /layout page
5. update article at /edit page. set body to "updated"
6. Open article /layout page
7. Article body is still "original"
8. Save layout
9. Article body is "updated"
Comment #41
ranjith_kumar_k_u commentedRerolled #33
Comment #42
pooja saraah commentedFixed Failed commands #41
Comment #43
ranjith_kumar_k_u commentedComment #45
rassoni commentedFixed Failed commands on #44
Attached interdiff
Comment #47
smustgrave commentedFixed deprecation errors and added a check for the route_name
Comment #48
tim.plunkettThat function is only in PHP 8 or later, if we intend to land this in D9 at all we need to support PHP 7
Comment #49
smustgrave commentedSorry guess I got ahead of myself.
Comment #51
shubham chandra commentedAdded Patch against #49 in Drupal 10.1.x
Comment #52
bnjmnm#51 was an unnecessary reroll that will not receive credit. It's also an incomplete reroll and misses several changes. Additional work should be based on #49, as #51 breaks several things. As I've mentioned to you several times @Shubham Chandra - you can check if a patch truly needs a reroll by clicking "add test/retest" on the most recent patch and applying it to the most recent Drupal version. Drupal getting a new version doesn't necessarily mean a reroll is needed.
As far as feedback on the #49, it looks like the test added should use stark as the default theme, this will allow it to work on both 9 and 10
Comment #53
stefdewa commentedUpdated test to use 'stark' instead of 'classy' as default theme.
Comment #55
luke.leberWe should probably enable the field_ui module here as well. I believe that 4 years ago, field_ui was required by layout builder, but that has since been decoupled.
This should fix the test failure, I believe :-)
I can confirm that #53 fixes the issue on 9.4.12. Here's a dumbed down condition that was reported to us:
Say there are three states:
and various transitions:
and an "Author" only has access to
Draft -> Draft,Draft -> Pending, andPublished -> Draft.Edittab, but not theLayouttab until changes are discarded!Following applying #53, authors have access to the
EditandLayouttabs appropriately.Sorry for the long-winded comment -- I can vouch for RTBC once the test fail is resolved.
Comment #56
rishabh vishwakarma commentedAdding field_ui as mentioned in #55
Comment #58
luke.leberDo'h! I think this class used to be added by the Classy theme! This test is now using Stark after #53!
A different CSS selector will have to be used -- I'm not sure off the top of my head exactly what that would be though.
Comment #59
ranjith_kumar_k_u commentedUpdated the CSS selector, and there is no specific CSS class on the Body field block in the Stark theme
<div data-layout-content-preview-placeholder-label=""Body" field" class="js-layout-builder-block layout-builder-block contextual-region" data-layout-block-uuid="3d159177-0c9a-4e57-bf47-6b5cce1e3fa3" data-layout-builder-highlight-id="3d159177-0c9a-4e57-bf47-6b5cce1e3fa3" draggable="false">That is why I updated the code like this
The other test failures from the file "core/modules/layout_builder/tests/src/FunctionalJavascript/FieldValuesTest.php" are because of the following issue
Allow field blocks to display the configuration label when set in Layout Builder
Comment #60
ranjith_kumar_k_u commentedComment #61
bnjmnmTests should typically be passing before an issue is set to "Needs Review", especially since it looks like the failure is related to the changes being made.
There are occasional exceptions, and in those cases there should be an explanation as to why it's getting set to "Needs Review" despite failing tests.
Comment #62
ranjith_kumar_k_u commentedHi, the last patch was failing tests due to the following issue https://www.drupal.org/project/drupal/issues/3039185, now that issue has been fixed on 10.1x and 11x, So here last patch tests are passing now.
Comment #63
smustgrave commentedIssue summary is incomplete. If that could be updated please.
Comment #66
taran2lSo, I've converted #59 to a MR, then fixed a few nitpicks.
My idea of modernizing it a bit is not working as expected, so I've given up on that
Please review
Comment #67
smustgrave commentedIssue summary looks good thanks!
Left some comments on the MR, mostly small stuff
Ran test-only feature
So coverage appears to be there.
Looks super close!
Comment #68
taran2lComment #69
smustgrave commentedFeedback appears to be addressed
Confirmed the issue described in the issue summary has been resolved
#67 mention the test coverage is there
Comment #70
tim.plunkettLeft some suggestions for nits, but also raised a few points that need to be addressed.
Comment #71
taran2lComment #72
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #73
taran2lBot seems to be wrong, latest MR passes everything and it contains latest changes from the core
Comment #74
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #75
smustgrave commentedComment #76
smustgrave commentedSo the review bot has been temporarily turned off as a bug is look at.
But appears the feedback has been addressed but will leave in review for @tim.plunkett to agree.
Comment #77
taran2lSo, there is one unresolved threadm everything else has been addressed afaik.
Comment #78
smustgrave commentedI've also seen using layout_builder__layout as a check has been discouraged before, see #2938129: PageTitle block is non-functional when not handled directly by \Drupal\block\Plugin\DisplayVariant\BlockPageVariant. Though the solution I came up with over there not too sure about, hoping @Tim.plunkett has some better trick.
Comment #79
smustgrave commented@Tim.plunkett do you have a different preferred approach or good to continue with what's there?
Comment #80
tim.plunkettI will try to look between now and the end of DrupalCon. For now, I'd consider this NW for finding a better way
Comment #81
jastraat commentedJust to confirm, this is still an issue with the latest release of Drupal 11.
Comment #82
jastraat commentedI rebased on Drupal 11 and moved the new entity update hook to the hook class with the rest. I'd like to throw this back out for review -
Comment #83
jasongose commentedThis works for me :)
Comment #84
catchThe feedback from Tim Plunkett on the MR hasn't been addressed, and I agree this should do something other than check the route, which feels brittle.
Comment #85
taran2l@catch, in #80 @tim.plunkett has self-assigned this issue and no progress for over a year ... is anyone has a better idea on how to overcome this issue without dependency on the route system?
Comment #86
luke.leberCrazy idea...but does it really matter if the tempstore entity is updated if the entity was saved with LB? Seems to me at face value that's a premature optimization. Can the route check just be removed...?
Comment #87
tim.plunkettComment #88
taran2lComment #89
taran2lImplemented @luke.leber suggestion, please review. This should be ready to go in now
Comment #90
smustgrave commentedTested this manually following the steps and did notice the text would update.
Would note I did have to discard my changes in layout builder AFTER I applied the MR for the change to take hold.
Comment #91
luke.leberre: #90 - honestly I think that's alright. Sites are no worse off than they are now and given the age of this issue, IMO it should be landed as-is. It at least prevents the situation from happening to new users even if certain rare(?) tempstores aren't automatically flushed.
Don't let perfect be the enemy of good here. 🙏
Comment #92
xjm#91 is correct, FWIW. While a TempStore is persistent (state) and therefore not invalidated by the normal update cache clear, it's exactly true that the user is no worse off: Their TempStore contained stale values before the update, and still will after the update. I don't think we would write an update hook to update a TempStore except under exceptional circumstances (security or data integrity issue, for example). According to the title and IS, this is a UX/user expectation problem, but not a data loss problem, so I don't think it merits an upgrade path for TempStores.
Comment #93
danielvezaI really hate to be a pain, if its an easy swap can we please make the test Functional instead of FunctionalJavascript? Layout Builder uses FunctionalJavascript tests for so much, even when no JS is required. I'm trying to move all tests (where possible) to Functional tests so ideally we'd avoid adding too many more.
From a glance I don't see anything here that needs it to be a FunctionalJs test. If I'm incorrect I'm happy for this to be RTBC in it's current state.
Comment #94
taran2lPer great suggestion by @danielveza, I have converted the test to Functional
Hope this can go in finally
Comment #95
smustgrave commentedLeft comments in MR.
Comment #96
taran2laddressed feedback
Comment #97
danielvezaThis has has many comprehensive reviews already, all feedback has been addressed. I've given it one last sweep, I think this is ready for RTBC
Comment #98
evilargest commentedA diff from the latest MR changes. Works fine on 11.2.4
Comment #100
catchThis is a tricky one but it looks good. Committed/pushed to 11.x, thanks!