Problem/Motivation
The inline block form is always loading the active block_content entity from the entity repository as long as it is not a new inline block or block_content. This is causing an issue in the following situation:
1) Create and save a node of a content type that allows layout builder overrides
2) Edit the layout to create the override, and add an inline block to any section.
3) Add block field data as desired and save the layout.
4) Go back to edit the layout.
5) Click to configure the existing inline block. Change field data to different values and update the block. Do not save the layout.
6) Click to configure the block again and notice that the block fields have stale data.
Proposed resolution
Issue seems to be in this code:
if (!$this->isNew && !$block->isNew()) {
// Get the active block for editing purposes.
$block = \Drupal::service('entity.repository')->getActive('block_content', $block->id());
}Checking whether inline block configuration contains serialized block data before loading the active entity from the entity repository should address it.
Remaining tasks
Needs tests.
| Comment | File | Size | Author |
|---|
Issue fork layout_builder_st-3067646
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
godotislateHere's a patch that adds a check for serialized block data.
Comment #3
tedbow@godotislate thanks for this! Sorry been so long
We need a test to prove the current problem and that we don't regress
Comment #4
bwaindwain commentedThis fixes the issue for our project. Thanks @godotislate!
+1
Comment #5
godotislateHere's a failing test. Includes fixes for unrelated tests so that they will pass.
Comment #6
godotislateUpdated test-only patch to resolve more issues and deprecations from other tests.
The JSONAPI test failure has to do with https://www.drupal.org/node/3042198, and the workaround there uses strict class check that fails on this class's
\Drupal\layout_builder_st\Entity\LayoutBuilderEntityViewDisplayComment #7
godotislatePatch with fix and test combined.
Comment #8
anybodyComment #9
ashwinshThe inline-block form is always loading the active block_content while editing.
Steps to reproduce:
- Navigate to LB page with a content inline-block which is having body field
- Update the body field of the same inline-block and save the changes
- Go to Revert and revert LB page to the previous revision
- See the content was reverted in LB to the previous content.
- Now try to edit the same inline-block.
- It always shows the latest content
Not sure but the issue seems to be in this code:
Comment #10
godotislateRe-roll.
Comment #11
anybodyGreat work @godotislate! RTBC+1!
@ashwinsh could you please test if patch #10 fixes the problem for you?
Comment #12
maacl commentedI am using this Patch for several months now, and got a bug report from a editor, that the content shown in the rendered inline block is not the same as while editing the block. When the block is loaded, there is no serialized content available and the edit-form loads the active revision of the block. The Drupal Core Layout Builder does someting different, it loads the revision referenced in the parent entity:
This is from getEntity() in
core/modules/layout_builder/src/Plugin/Block/InlineBlock.php, and looking further, this method already checks if there is a serialized block, but uses a different method to load the block. So in my case, this still leads to loading of different revisions of the block. Unfortunately I am not sure, what steps lead to it, but I am seeing something similar deleting a translation of a node, an create that translation again.Revisions for the bundle are enabled, but I am blocking the reverting of revisions and there is no content moderation or workflow with forward revisions.
At this moment, I am not sure, if core should also load the active revision. I am testing overwriting the getEntity()-Method in the InlineBlock-Class from this module for now, to also load the active revision.
Comment #13
didebruFor us the patch #10 is working thank you!
Comment #14
justcaldwell#10 is working for us as well — another +1 for RTBC.
I don't think I understand #12 well enough to try to replicate.
Comment #15
s_leu commentedCan confirm that #10 is still applying and working for us too. As 3 people confirmed that this is working and the patch contains tests, I'm taking the liberty of marking this as RTBC.
Comment #16
gordonio commentedI believe I am seeing the same issues as #12, but for the most part it's working fine. It was reproducible when I had more than two languages.
What I was seeing was:
It appears to be unrelated to this module and there is a thread for what I believe is the same issue here: https://www.drupal.org/project/drupal/issues/3240993
Comment #17
heddnComment #19
heddnHiding patches and rolling #10 into an MR.
Comment #21
heddnThanks for the fixes here.
Comment #23
joseph.olstad@heddn, since layout_builder_st 2.0.x pipeline/tests are passing for Drupal 10 and Drupal 11.1 , would be great if you could tag an alpha or beta or rc release for 2.0.x prior to dealing with 11.2/11.3 since we're still using 11.1.9 and a lot of folks are using Drupal 10 still.