Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Steps to reproduce:
- Enable CM and layout.
- Enable moderation on nodes, enable customising layouts on individual nodes.
- Create a published item of content.
- Create a new draft of that content, make some changes.
- Change some part of the layout for that item of content.
- Data in the pending revision is overridden by a new default revision, although it is still available in the DB.
Proposed resolution
Adapt the new API from #2942907: Entity system does not provide an API for retrieving an entity variant that is safe for editing
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#56 | 2942675-getactive-56-interdiff.txt | 883 bytes | tim.plunkett |
#56 | 2942675-getactive-56.patch | 11.53 KB | tim.plunkett |
#54 | 2942675-getactive-54-PASS.patch | 11.68 KB | tim.plunkett |
#54 | 2942675-getactive-54-FAIL.patch | 1.9 KB | tim.plunkett |
#48 | 2942675-getactive-48.patch | 9.78 KB | tim.plunkett |
Comments
Comment #2
larowlanComment #3
tim.plunkettSee also #2937199: Track Layout override revisions on entities which support revisioning
Comment #4
larowlanMy thinking here is that LB should work with CM, in so far as a new layout should be a new pending revision.
Comment #5
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedIf layouts simply loaded the latest revision:
The only question is, who is responsible for doing that.
Comment #6
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAdded steps to reproduce.
Comment #7
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #8
larowlanData loss makes this critical
Comment #9
larowlanShould be job of LB?
Comment #10
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #11
tim.plunkettMost of
\Drupal\Core\ParamConverter\EntityConverter
has nothing to do with param converters, it's just "the right way to load entities for editing/displaying".If that was abstracted to a service, I think the right method calls added to
\Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::getSectionListFromId()
would solve this.Comment #12
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commented@larowlan it's only the job of layout builder if we make a decision with regards to how to other modules should treat pending revisions. Currently without a path forward on that, CM is already required to hook into other parts of core to enforce those semantics.
Comment #13
tim.plunkettThis REALLY needs functional tests to validate that it's the behavior we want.
But this might be a start, as I understand the problem?
Comment #15
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #16
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #17
tim.plunkettOops, had other code applied locally.
Anyway, I think this should NOT be Layout Builder's responsibility at all. There should be an API method on a service for loading a mutable entity, and we should call that instead of
$this->entityTypeManager->getStorage($entity_type_id)->load($entity_id);
which should be banned from usage in code that presents user-facing data.Comment #18
EclipseGc CreditAttribution: EclipseGc at Acquia commentedTim brought up the comparison of get() vs getEditable() for config objects, and that really resonated as a good analogy to me on this topic. I think it's fine that layout_builder acknowledges that it needs to make concessions to some other system in order to get the particular version of the entity it needs, but that could be revision, or revision of a particular language, or any number of unforeseen criteria that may come to light at some point in the future. As it is, this patch hard-codes the logic which should probably exist in a real api somewhere. If we had a central service that could negotiate that, I bet stuff like content_moderation would get a lot easier and we'd not have to play whack-a-mole with all the new modules that come along that we wish we could integrate with.
Eclipse
Comment #19
plachUpdated the IS to clarify that we are not talking about data loss, but pending revision data being overridden by new default revision data.
In that light I'm not sure this should be critical, given that Layout Builder is still experimental. Not changing the priority, since this will for sure be discussed during the next triage call.
Comment #20
plachBtw, what #17 is suggesting looks very similar to what Sam is suggesting in the OP. Unfortunately, even if we had that, it still one more concept to deal with, but I'm afraid there's no way around that.
Comment #21
plachBtw, this is not even correct from the multilingual perspective. So one more reason to add an API to encapsulate this logic.
Comment #22
tim.plunkettHere's what I think Layout Builder needs. The rest is up to Drupal\Core\Entity to solve.
Comment #24
tim.plunkettI am downgrading and blocking this on #2942907: Entity system does not provide an API for retrieving an entity variant that is safe for editing.
Comment #25
tim.plunkettComment #26
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedRepurposing this issue based on the latest discussion in #2940575: Document the scope and purpose of pending revisions.
Comment #27
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #28
plachLet's start using the "active revision" terminology :)
Comment #29
tim.plunkettTagging as this is currently on our shortlist.
Comment #30
tim.plunkettNo one is actively working on this.
Comment #32
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAdding a test for the integration between layout builder and content moderation. Should be useful regardless of the solution which ends up making these two work together.
Comment #34
xjmI think this is still critical, because even if #2942907: Entity system does not provide an API for retrieving an entity variant that is safe for editing is addressed the data integrity issue is still there until LB and/or CM implement it.
Comment #35
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThere was some discussion at Drupal Europe which impacts the layout builder/content moderation integration, which I summarised in the issue summary here: #3004536: Move the Layout Builder UI into an entity form for better integration with other content authoring modules and core features.
To quote the part relevant to content moderation:
I think it makes sense to postpone this issue on some discussion over there. If it turns out the proposal is not viable, we'll need to pick this back up.
Comment #36
tim.plunkettWill read the above issue.
Comment #37
nadavoid CreditAttribution: nadavoid at Phase2 commentedIs there a new temporary shim to help with this problem? The temporary shim being to have layout builder always load the latest revision.
I was using the patch in #17 (https://www.drupal.org/files/issues/2942675-layout_revision-15.patch), but it no longer applies to the latest version of core, currently 8.6.7. Also, manually applying its updates didn't make any difference since the method affected is deprecated and layout builder is apparently no longer using these deprecated methods.
The patch in #22 (https://www.drupal.org/files/issues/2942675-layout_entity_thing-22.patch) doesn't apply either. It looks like it prepares for a solution, but on its own, doesn't provide a workaround.
Comment #38
tim.plunkettHere's a reroll of #17 for 8.6 and 8.7
I would also recommend following #2946333: Allow synced Layout override Translations: translating labels and inline blocks
Comment #39
nadavoid CreditAttribution: nadavoid at Phase2 commentedThank you for the reroll Tim! I've successfully applied it on top of the patch in #2986394: 2.x patch reroll issue (I'm using lightning which includes lightning layout), and it seems to be working as expected now. I realize this is kind of a superficial fix to a really tricky problem, so I'll try to follow along with the other related issues.
Comment #40
Panchotypo
Comment #41
tim.plunkettHere's a more heavy handed approach building off of #2942907-84: Entity system does not provide an API for retrieving an entity variant that is safe for editing.
Going to use this patch alongside other issues to help prove their test coverage.
Comment #43
tim.plunkettAccidentally included the test from #2973860: When there is an entity forward revision for Content Moderation and a layout override is saved the revision is no longer latest here. Removing that.
Also changing the prophecy until the new methods are on the interface.
Comment #44
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commented@tim.plunkett Are you intending for this to be committed or do you consider #2942907: Entity system does not provide an API for retrieving an entity variant that is safe for editing a blocker?
I'm assuming a committer would apply the same level of scrutiny to the entity repository changes here, so this patch being ready would essentially mean the blocker is also ready for commit?
Comment #45
tim.plunkettI'm not sure how hard to push on this.
Mostly it's an easier means for other issues to be tested than having to apply both the most recent version of that patch plus the internal changes, but updated for the method names du jour.
The internals of the other issue haven't changed in a bit.
This is also an escape hatch if the other issue stalls out and we need something to help fix all these stable blockers.
Comment #46
tim.plunkettComment #47
tim.plunkett#2942907: Entity system does not provide an API for retrieving an entity variant that is safe for editing landed!
Let's repurpose this for using the new API?
Or close it as a dupe and implement this in an issue with tests (like #2973860: When there is an entity forward revision for Content Moderation and a layout override is saved the revision is no longer latest)?
Comment #48
tim.plunkettComment #49
johnwebdev CreditAttribution: johnwebdev commentedWe could commit as-is, but I'd definitely prefer we get the test coverage from the issues that had been blocked by this API with us.
Patch looks great.
Comment #50
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedEach issue that depends on this issue will have it's own test coverage which will include both implicit test coverage for this issue as well as the logic within the new API itself. Along with the
OverridesSectionStorageTest
unit test and all the existing functional testing going green, I think the test coverage is okay.Tentatively RTBC, will see what committers think.
Comment #52
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedComment #53
plachThe patch looks good to me, I manually tested it and it indeed fixes the reported issue. However test coverage looks a bit shallow: what about adding a functional test simply checking that the latest revision is loaded on the
/node/{node}/layout
route when we are dealing with a pending revision? We could create a pending revision manually to avoid having to set up Content Moderation.No deprecation/BC layer here: I guess that's fine given that we are in an experimental
@internal
plugin.Comment #54
tim.plunkettGood idea, I feel much better having a functional test here.
FAIL patch is equivalent to the interdiff
Comment #55
phenaproximaWhy wouldn't getTranslationFromContext() be called? Maybe this line should have a comment explaining the train of thought here.
Otherwise, every line in this patch makes crystal clear sense to me.
Comment #56
tim.plunkettThat check for no calls to getTranslationFromContext was helpful when debugging this, but keeping it in here now is coupling this too closely to knowledge of the internals of EntityRepository. Removed
Comment #57
phenaproximaThanks, @tim.plunkett! RTBC once Christmas-ey.
Comment #59
plachNice spot! That indeed looked suspicious :)
Comment #60
plachSaving credits
Comment #61
plachCommitted 17de81c and pushed to 8.7.x. Thanks!
Comment #63
xjm