Blocked behind #3053887: Add test coverage and document why inline blocks require a new revision to be created when modified, regardless of whether a new revision of the parent has been created

Problem/Motivation

When reverting a parent entity revision, the parent/child relationship looks like:

 +------------+   +------------+   +------------+
 |Host Entity |   |Host Entity |   |Revert VID 1|
 |VID: 1      |   |VID: 2      |   |VID: 3      |
 |Timestamp: 1|   |Timestamp: 2|   |Timestamp: 3|
 +------------+   +------------+   +------------+
       |                |                |
       v                v                |
 +------------+   +------------+         |
 |Block Entity|   |Block Entity|         |
 |VID: 1      |   |VID: 2      |         |
 |Timestamp: 1|   |Timestamp: 2|         |
 +------------+   +------------+         |
       ^                                 |
       +---------------------------------+

 Custom block entity form
 +-----------------------------+
 |$saved_entity change time: 2 |
 |$new_entity change time: 1   |
 |Validator throws error       |
 +-----------------------------+

When block entity VID 1 is loaded into the custom block form, the validator compares it against VID 2 as the "saved entity". The validator sees that a new revision has been created since VID 1 and throws an error.

Node handles this by updating the changed timestamp in \Drupal\node\Form\NodeRevisionRevertForm::submitForm when a node is reverted, but there isn't currently a process to create new entity revisions of custom blocks when a host entity is reverted.

Steps to reproduce

  1. Create a node and add a basic block to it via LB
  2. Create a new revision, and edit the block
  3. Revert to the first revision via the Revisions screen
  4. Try to edit the block again, on save you will trigger the constraint and get the error message "The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved."

Proposed resolution

Create a modified version of EntityChangedConstraint for BlockContent entities that skips the constraint validation for non-reusable (also known as "inline") block entities. This validation constraint is not necessary for inline block entities because Layout Builder is already creating new revisions of blocks when the layout is saved (see \Drupal\layout_builder\InlineBlockEntityOperations::handlePreSave). There's no danger of losing content.

Remaining tasks

We're so close. One remaining task:

User interface changes

None

API changes

Block content entities will no longer use the Drupal\Core\Entity\Plugin\Validation\Constraint\EntityChangedConstraint, but will now use Drupal\block_content\Plugin\Validation\Constraint\BlockContentEntityChangedConstraint, which extends Drupal\Core\Entity\Plugin\Validation\Constraint\EntityChangedConstraint instead.

Data model changes

None

Release notes snippet

TBD

CommentFileSizeAuthor
#100 3053881 after patch.png22.41 KBaarti zikre
#100 3053881 before patch.png98.09 KBaarti zikre
#98 3053881-99.patch5.79 KBrishi.kulshreshtha
#98 interdiff_82-99.txt1.92 KBrishi.kulshreshtha
#91 3053881-82-test-only.patch2.02 KBluke.leber
#82 interdiff_68-82.txt1.31 KBluke.leber
#82 3053881-82.patch5.77 KBluke.leber
#81 interdiff_68-81.txt1.41 KBluke.leber
#81 3053881-81.patch5.86 KBluke.leber
#80 Screenshot 2022-03-16 at 3.15.31 PM.png106.64 KBjoshua1234511
#68 3053881-68.patch5.77 KBluke.leber
#67 3053881-67.patch5.21 KBluke.leber
#64 interdiff_60-64.txt2.11 KBluke.leber
#64 3053881-64-TEST-ONLY.patch3.6 KBluke.leber
#64 3053881-64.patch7.66 KBluke.leber
#60 3053881-60-TEST-ONLY.patch1.99 KBbkosborne
#60 3053881-60.patch7.63 KBbkosborne
#57 3053881-57-TEST-ONLY.patch1.99 KBbkosborne
#57 3053881-57.patch7.68 KBbkosborne
#54 3053881-54.patch8.8 KBrishi.kulshreshtha
#49 interdiff_47-49.txt792 byteschrisolof
#49 3053881-49.patch4.67 KBchrisolof
#47 3053881-47.patch4.66 KBkyberman
#45 interdiff_44-45.txt551 bytestyler-paavola
#45 3053881-3049332-45.patch8.82 KBtyler-paavola
#44 interdiff_42-44.txt6.97 KBtyler-paavola
#44 3053881-3049332-44.patch8.82 KBtyler-paavola
#43 3053881-43.patch3.52 KBodai atieh
#42 interdiff_34_42.txt1.73 KBtyler-paavola
#42 3053881-42.patch3.31 KBtyler-paavola
#34 3053881-34.patch3.29 KBOscaner
#30 3053881-30.patch7.12 KBacbramley
#28 3053881-28.patch1.51 KBethomas08
#15 3053881-2946333-3053887-COMBINED.patch142.46 KBsam152
#11 3053881-11.patch6.96 KBsam152
#10 3053881-10.patch2.06 KBsam152

Issue fork drupal-3053881

Command icon 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

Sam152 created an issue. See original summary.

sam152’s picture

Issue summary: View changes
sam152’s picture

Issue summary: View changes
sam152’s picture

I'm trying to think of the best approach here. I think inline blocks may simply need to opt out of this constraint, since the validation against overriding other peoples work will happen on the host entity anyway.

The only thing I want to validate here is: modifying "Block Entity VID 1" in the diagram results in VID 3 being created and associated with parent entity VID 3, instead of rewriting history.

sam152’s picture

Issue tags: +Blocks-Layouts

I can see there being two options to resolve this while maintaining integrity:

  1. Copy on revert: Force a bump in all custom block revisions when an entity is reverted, bump the changed timestamps of these copies, then in the future custom blocks can safely not create new revisions without rewriting history.
    This would require no changes to the validator, the "changed" timestamp would be bumped when the revision was copied.
  2. Copy on save: Allow new parent revisions to double-reference previous block revisions, but always force a new revision on save. That way there is no danger of rewriting history when users have elected to not bump a revision in the parent.
    The validator would need to be switched off inline blocks

Currently new revisions are being enforced in \Drupal\layout_builder\InlineBlockEntityOperations::handlePreSave, with a todo pointing to #2937199: Track Layout override revisions on entities which support revisioning, which has made some progress towards not enforcing new block revisions.

Here are some reasons why I think option 2 is the correct approach:

  1. There will be databases in this state already, writing an upgrade path that duplicates block content revisions and updates parent entity revisions would be a large and complex update hook that iterates potentially all content entities with LB enabled. In my experience, not writing the update hook would result in a consistent dribble of bugs, (see: burned by a content moderation bugfix #3020448).
  2. The fix is likely quite a small self-contained adjustment to the validator that excludes inline blocks.
sam152’s picture

It looks like \Drupal\layout_builder\Plugin\Block\InlineBlock::saveBlockContent already attempts to create a new block revision on parent save, but it only does so if the block content was serialized, ie it was loaded into the sidebar and saved by a user.

For that reason, there are a lot of parent entity revisions which reference common content block revisions. For any entity that has 2 or more custom blocks, new revisions of a parent are only correlated with new revisions of the child block content when those children were actually modified from the UI. For that reason, I think it entirely rules out option 1, it's simply not how the data model was designed.

I think given that's the case, there also needs to be a way more explicit code path that explicitly decouples revision handling from the serialized asepct of custom blocks.

sam152’s picture

Title: Reverting entity revisions that contain custom blocks erroneously trigger EntityChangedConstraint » Reverting entity revisions that contain custom blocks erroneously triggers EntityChangedConstraint
sam152’s picture

Title: Reverting entity revisions that contain custom blocks erroneously triggers EntityChangedConstraint » [PP-1] Reverting entity revisions that contain custom blocks erroneously triggers EntityChangedConstraint
Issue summary: View changes
sam152’s picture

Status: Active » Needs review
StatusFileSize
new2.06 KB

Test to reproduce this.

sam152’s picture

StatusFileSize
new6.96 KB

Here is a possible implementation for this.

The last submitted patch, 10: 3053881-10.patch, failed testing. View results

tedbow’s picture

Adding related issues

I ran into a similar issue in #2946333: Allow synced Layout override Translations: translating labels and inline blocks because editing a translation of layout and editing the inline block would cause a similar problem. In that case the inline blocks are also translations and when you create a translation you create a new revision of the block.

In that case I am trying to solve it in the issue with this #3052042: If an inline block has been edited outside of layout builder it can't be edited in layout builder

If we take the approach in this issue and we edit the previous revision of the block would we lose the translation in the new revision?

sam152’s picture

I'm not sure what the impact this has on the translation work.

Regardless of this issue though, with all the changes to revisions and translations, I think the test coverage in #3053887: Add test coverage and document why inline blocks require a new revision to be created when modified, regardless of whether a new revision of the parent has been created would probably be pretty valuable?

Status: Needs review » Needs work

The last submitted patch, 15: 3053881-2946333-3053887-COMBINED.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

sam152’s picture

Status: Needs work » Needs review

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.

chris burge’s picture

I closed #3087882: Impossible to update inline blocks after reverting to a previous revision as a newer duplicate of this issue.

In summary, here's the direction that discussion on that issue was headed:

When a revisionable a host entity is reverted, new revisions of its inline blocks are also created with those block revisions being referenced by the entity's layout builder field.

sam152’s picture

I explored that in #5, however was put off by the fact that it is significantly more complex and would require a gnarly upgrade path for installations that are already in the current shared references state.

bkosborne’s picture

Priority: Normal » Major

I think this is better classified as a major, no? This bug prevents editors from editing a block's contents in LB after reverting the parent entity.

chris burge’s picture

Re #21, agreed. The repercussions are significant, and there's no viable workaround.

tim.plunkett’s picture

Status: Needs review » Postponed

Per #9, this is postponed.

acbramley’s picture

This is extremely easy to reproduce as per the test

  1. Create a node and add a basic block to it via LB
  2. Create a new revision, and edit the block
  3. Revert to the first revision via the Revisions screen
  4. Try to edit the block again, on save you will trigger the constraint and get the
    The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.
    

    error

poindexterous’s picture

I ran into the same issue as acbramely after my latest round of drupal and 3rd party module updates, but it was happening with inline paragraph blocks as well. Patch #11 seems to work to solve the problem for me.

azovsky’s picture

I have the same issue as described in #24 (thanks @acbramley).
And the patch from #11 fixed my issue (thanks @sam152)!

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

ethomas08’s picture

StatusFileSize
new1.51 KB

Adding a patch for 8.7.14 that works to opt the inline custom blocks out of the entity constraint validation.

pyrello’s picture

#11 applied and resolved the issue for me. Thanks!

acbramley’s picture

StatusFileSize
new7.12 KB

Rerolled against 9.1.x, BlockContentUpdateTest was removed as part of #3087644: Remove Drupal 8 updates up to and including 88** so this adds it back again.

acbramley’s picture

Issue tags: +Bug Smash Initiative
sam152’s picture

Status: Postponed » Active
tim.plunkett’s picture

Title: [PP-1] Reverting entity revisions that contain custom blocks erroneously triggers EntityChangedConstraint » Reverting entity revisions that contain custom blocks erroneously triggers EntityChangedConstraint
Oscaner’s picture

StatusFileSize
new3.29 KB

I readed #5, but don't know why no set a changed time when InlineBlock::blockValidate(), it will not affect any behavior of the current system.

edwardsay’s picture

#34 has resolved issue with "The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved." message when saving inline block in Layout Builder. Thanks.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

beanjammin’s picture

#34 worked for me, thank-you!

azinck’s picture

#34 is fixing the problem for me, too.

sam152’s picture

I don't think it makes sense to update entity values in a validate function, so a later validator is tricked into passing. I think #30 is probably a better approach.

azinck’s picture

Now that I look at it more closely I do agree with Sam152...however I'm going to keep using #34 until #30 lands in order to avoid introducing an update hook via a patch.

brooke_heaton’s picture

#34 is working for me.

tyler-paavola’s picture

StatusFileSize
new3.31 KB
new1.73 KB

#34 resolved the issue while using Drupal 8.9.x

#34 fails to apply after updating to Drupal 9.1.x

Reroll of #34 for 9.1.x (while #30 is developed as per Sam152 #39 & azinck #40).

odai atieh’s picture

StatusFileSize
new3.52 KB

I added this patch to be working with
https://www.drupal.org/project/drupal/issues/3049332

tyler-paavola’s picture

StatusFileSize
new8.82 KB
new6.97 KB

As Odai Atieh mentioned in #43, Drupal Issue #3053881 conflicts with #3049332 as both attempt to modify InlineBlock's constructor signature.

Unfortunately, #43 fails to apply using Drupal 9.1.4

I've combined #3053881's #34 with #3049332's #56 here in #44. Alternatively, #3049332's older #33 patch works cohesively with #3053881's #34 on its own, as it does not add LoggerInterface to InlineBlock's constructor's signature.

> Unable to provide an interdiff between #43 and #44 due to "interdiff: Whitespace damage detected in input" error, however attached is an interdiff between my previous #42 patch and #44.

>> I'll mention the conflict between these two issues' solutions in #3049332 as well.

tyler-paavola’s picture

StatusFileSize
new8.82 KB
new551 bytes

Oops, fixed "Parameter comment indentation" error from failed tests in #44

Note, as mentioned in #44, this patch combines #3053881's #42 (aka #34 for D9) with #3049332's #56

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kyberman’s picture

StatusFileSize
new4.66 KB

Thank you for all the patches, but for my scenario (content blocks nested in content block), none of the patches worked, unfortunately.

But the approach in #30 works nicely for 9.1.9, with these changes:
1) removed the whole "block_content_update_8700" function
2) removed the related "BlockContentUpdateTest" class
3) reversed the "BlockContentEntityChangedConstraintValidator" condition logic, so instead of:
if ($entity instanceof BlockContentInterface && !$entity->isReusable()) {
I used:
if ($entity instanceof BlockContentInterface && $entity->isReusable()) {

I'm not sure if this is the best way, but at least it solves the urgent situation.

kim.pepper’s picture

Issue tags: +#pnx-sprint
chrisolof’s picture

StatusFileSize
new4.67 KB
new792 bytes

#47 did not work for me. Reverting the condition logic reversal in core/modules/block_content/src/Plugin/Validation/Constraint/BlockContentEntityChangedConstraintValidator.php does seem to work, however. I think this brings that logic back to what it was in #30.

I would guess the update hook in #30 is necessary, but leaving it out doesn't seem to affect things on my installation, and my status page is clear of any entity definition mismatch warnings. Unfortunately I don't have time to research this area any further at the moment - just sharing my experience.

New patch attached. It's essentially the patch from #47 with that one small logic change (see the interdiff).

chamilsanjeewa’s picture

#49 Not worked for me.

robbt’s picture

So from my experience #42 works if anyone is wanting to patch a 9.2 site, I think that all patches after this would require applying multiple patches as they were modified to fit with other in-progress 9.3 changes.

smustgrave’s picture

Sorry if I'm repeating #51 but which patch is addressing the issue here? Is it #42? The other patches seem to be including other tickets are they needed?

Have the issue where a user is unable to save their inline blocks and #42 seems to initially work. #49 does not but I don't know if it's because of the additional changes it includes.

So some clarity would be greatly appreciated!

smustgrave’s picture

Using #45 and it seems to be working so far.

rishi.kulshreshtha’s picture

Status: Active » Needs review
StatusFileSize
new8.8 KB

As mentioned in #53, the patch provided at #45 works as expected, backporting the same to 8.9.x version as well.

Status: Needs review » Needs work

The last submitted patch, 54: 3053881-54.patch, failed testing. View results

bkosborne’s picture

Issue summary: View changes

Trying to get this back on track with Sam's original approach. Updated the issue summary as such.

bkosborne’s picture

Issue summary: View changes
StatusFileSize
new7.68 KB
new1.99 KB

Here's the patch from #30, unchanged except for comments added which I think were needed. This is Sam's original approach. Also uploading a test-only patch to prove that the test is valid.

Updated issue summary to describe the alternate approach that is represented in most of the more recent patches. I agree with #39 and #40 that it's not the best approach.

bkosborne’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 57: 3053881-57-TEST-ONLY.patch, failed testing. View results

bkosborne’s picture

Status: Needs work » Needs review
StatusFileSize
new7.63 KB
new1.99 KB

Removed unused use statement.

The last submitted patch, 60: 3053881-60.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 60: 3053881-60-TEST-ONLY.patch, failed testing. View results

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

luke.leber’s picture

StatusFileSize
new7.66 KB
new3.6 KB
new2.11 KB

Changes since #60:

  1. Switched the upgrade path test fixture from 8.8.0 to 9.0.0.
  2. Resolved drupalPostForm deprecations in \Drupal\Tests\layout_builder\FunctionalJavascript\InlineBlockTest

This should fix the upgrade path test + deprecations in #60...but can someone explain why we need an update hook implementation for this? On the surface it seems that an entity type alter should do the trick? Is it simply to trigger a cache rebuild?

I'm not entirely convinced that the update test is really testing what it's intended to.

Thanks! :-)

acbramley’s picture

but can someone explain why we need an update hook implementation for this

You know what, I think you're right. Alter hooks don't require an update hook to solidify what they're doing, they're altering existing definitions. We should instead just have an empty post-update hook to clear caches as you say. That means we can remove the update path test entirely!

Would be good for someone else to confirm.

larowlan’s picture

I think update hooks are only needed for entity-type changes that impact the database.

So I think what @acbramley is saying is correct.

You can alter an entity-type to add a new constraint without needing an update hook.

luke.leber’s picture

StatusFileSize
new5.21 KB

Thanks for the guidance! Hopefully a less risky fix can accelerate the resolution of this nasty little bug.

luke.leber’s picture

StatusFileSize
new5.77 KB

Add an empty post_update() hook to trigger a cache rebuild.

/**
 * Updates the entity changed constraint implementation.
 */
function block_content_post_update_entity_changed_constraint() {

}
luke.leber’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 68: 3053881-68.patch, failed testing. View results

luke.leber’s picture

I think that the test fails in #68 may be red herrings. I see a similar "random" fail in the latest patch in https://www.drupal.org/project/drupal/issues/3192234 (an unrelated issue).

luke.leber’s picture

Status: Needs work » Needs review

rajab natshah’s picture

Tested the 3053881-68.patch with Drupal 9.3.x
Thank you Luke

luke.leber’s picture

luke.leber’s picture

Issue summary: View changes

Update I.S. to remove data model change.

xjm’s picture

Priority: Major » Critical

This is data-loss-like so promoting to critical.

larowlan’s picture

Looks good to me, haven't manually tested yet though.

Super-nit:

+++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php
@@ -662,4 +662,46 @@ class InlineBlockTest extends InlineBlockTestBase {
+    $this->drupalLogin($this->drupalCreateUser([
+      'access contextual links',
+      'configure any layout',
+      'administer node display',
+      'administer node fields',
+      'administer nodes',
+      'bypass node access',
+      'create and edit custom blocks',
+    ]));
+    $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default');
+    $this->submitForm(
+      ['layout[enabled]' => TRUE, 'layout[allow_custom]' => TRUE],
+      'Save'
+    );

Can we do this via the API instead?

Saves an extra 2 HTTP requests in the test.


$display = \Drupal::service('entity_display.repository')->getViewDisplay('node', 'bundle_with_section_field');
assert($display instanceof \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay);
$display->enableLayoutBuilder()->setOverridable()->save();

joshua1234511’s picture

StatusFileSize
new106.64 KB

- Manually tested the issue with the test steps from issue summary.
- Issue has been resolved with the latest patch from #68
- Before Patch: before patch
- After Patch: https://nimb.ws/vawIBA

Can be marked as RTBC after question from #79 are resolved.

luke.leber’s picture

StatusFileSize
new5.86 KB
new1.41 KB

Made the requested change in #79.

luke.leber’s picture

StatusFileSize
new5.77 KB
new1.31 KB

Remove unneeded assertion.

luke.leber’s picture

Issue summary: View changes

Cleaned up IS.

Sam's question from #6 was related to attempting to copy revisions on revert. This is not the path that the patch took.

luke.leber’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 82: 3053881-82.patch, failed testing. View results

luke.leber’s picture

Status: Needs work » Needs review

Setting back to NR. I blame random fails still.

:(

luke.leber’s picture

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

simgui8’s picture

#82 fixed the error for me.

Thanks

kristen pol’s picture

Since the test code changed, it would be nice to have a test-only patch to make sure that fails before the fix.

luke.leber’s picture

StatusFileSize
new2.02 KB

Attach test-only fail patch as requested in #90.

omahm’s picture

Thanks for your work on this, I tried #68 on my site and the issue persists.
Steps to reproduce are:

  1. Create a new LB page and save as draft
  2. Edit the layout, add a section and any block and save as a draft
  3. Edit the layout (again), edit the block added in step 2, and again save as draft
  4. Select “Show revisions” from tasks menu and revert to the revision created in step 2 (the second oldest revision)
  5. Edit the layout yet again, and try to edit the block. When you try to save changes to the block (by selecting “Update”) you’ll get the error message "The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved."
luke.leber’s picture

Thanks for testing the patch out, @omahm.

Can you double check that you cleared caches after applying #82 please? It was my understanding that the old constraint validation should be completely bypassed for inline blocks, meaning that what you're seeing _should be_ impossible with the patch applied and caches flushed.

I won't have time this week to write a fail test, so if you want to take a swing at it, please don't hesitate to. :-)

Cheers

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Verified #82 fixes the issue following the steps in the description.

catch’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/block_content/block_content.post_update.php
    @@ -13,3 +13,10 @@ function block_content_removed_post_updates() {
     }
    +
    +/**
    + * Updates the entity changed constraint implementation.
    + */
    +function block_content_post_update_entity_changed_constraint() {
    +
    +}
    

    The comment makes it look like the empty post update is a mistake. It should mention that it's added purely to flush caches.

  2. +++ b/core/modules/block_content/src/Plugin/Validation/Constraint/BlockContentEntityChangedConstraintValidator.php
    @@ -0,0 +1,30 @@
    +   * {@inheritdoc}
    +   */
    +  public function validate($entity, Constraint $constraint) {
    +    // Don't validate "inline" (i.e. non-reusable) block content entities
    +    // as this prevents saving an update to the block form on a reverted host
    +    // entity's layout in layout builder. This is safe because inline blocks
    +    // are not actually saved until the whole layout is saved, in which case
    +    // Layout Builder forces a new revision for the block.
    ...
    +    if ($entity instanceof BlockContentInterface && !$entity->isReusable()) {
    +      return;
    +    }
    

    I'm not sure the comment shows enough why we have to change this.

    This is a problem when the host entity is changed outside of the entity form, not only a revision revert I think?

    Layout builder is the only implementation of inline blocks we have in core, but there could be others later or in contrib. Given this code is in block module, I think it should mention layout builder as being an example of this problem.

    Something like:

    'This prevents saving an update to the block via a host entity's form, if the host entity has had other changes made via the API instead of the entity form, such as a revision revert. For example... [layout builder-specific stuff]".

larowlan’s picture

Issue tags: +Novice

Updating the comment is a Novice task

Webbeh’s picture

Issue summary: View changes

Updating IS for last step - let's get that patch rerolled with changes.

rishi.kulshreshtha’s picture

Status: Needs work » Needs review
StatusFileSize
new1.92 KB
new5.79 KB

Updated comments as prescribed by @catch in #95

aarti zikre’s picture

Assigned: Unassigned » aarti zikre

reviewing this

aarti zikre’s picture

Assigned: aarti zikre » Unassigned
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new98.09 KB
new22.41 KB

Verified #98 patch.

Testing steps:
# Created new instance of drupal 9.5.x
# Create a node and add a basic block to it via LB
# Create a new revision, and edit the block
# Revert to the first revision via the Revisions screen
# Try to edit the block again.

Problem:
on save you will trigger the constraint and get the error message "The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved."

Expected output:
on save content should be save without any error

Test Result:
we can save the content with any issue.
this new patch included all the changes mentioned by the #95.

Attaching SS for reference.

Before:
2022-08-04/3053881 before patch.png
After:
2022-08-04/3053881 after patch.png
Can be moved to RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Fixed
+++ b/core/modules/block_content/block_content.post_update.php
@@ -13,3 +13,10 @@ function block_content_removed_post_updates() {
+/**
+ * Added purely to flush caches.
+ */

This text appears in the UI. It has different rules than regular function text. It should be about why we actually have the update function. So
Clear the entity type cache.

We also tend to comment empty functions. Here's an example from 9.4.x...

/**
 * Clear the source count cache.
 */
function migrate_post_update_clear_migrate_source_count_cache() {
  // Empty post_update hook.
}

Given this is a critical issue I've made the changes on commit.

diff --git a/core/modules/block_content/block_content.post_update.php b/core/modules/block_content/block_content.post_update.php
index 8e88fd0ffd..8e707e9099 100644
--- a/core/modules/block_content/block_content.post_update.php
+++ b/core/modules/block_content/block_content.post_update.php
@@ -15,8 +15,8 @@ function block_content_removed_post_updates() {
 }
 
 /**
- * Added purely to flush caches.
+ * Clear the entity type cache.
  */
 function block_content_post_update_entity_changed_constraint() {
-
+  // Empty post_update hook.
 }

Committed and pushed 7362bc50b2 to 10.1.x and 8672c43544 to 10.0.x and 6a261489b6 to 9.5.x. Thanks!

  • alexpott committed 7362bc5 on 10.1.x
    Issue #3053881 by Luke.Leber, bkosborne, tyler-paavola, Sam152, Rishi...

  • alexpott committed 8672c43 on 10.0.x
    Issue #3053881 by Luke.Leber, bkosborne, tyler-paavola, Sam152, Rishi...

  • alexpott committed 6a26148 on 9.5.x
    Issue #3053881 by Luke.Leber, bkosborne, tyler-paavola, Sam152, Rishi...

Status: Fixed » Closed (fixed)

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