Problem/Motivation

When inline entity is edited, it will cause validation error upon saving entity: "The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved."
This will happen only if 'changed' field of entity is newer then 'changed' of node. This situation can happen if same entity is referenced in two different nodes.

Steps to reproduce

  • Create a node and create a new inline entity
  • Create another node and reference the same entity
  • Edit first node and try updating inline entity
  • Validation error is shown

What's happening

This happens because upon form submission all node fields are copied to entity fields. Including 'changed' field. Now entity gets changed time which is older then stored changed time of entity. Therefore system thinks that there is a newer stored entity by someone else.

This happens during form validation:

  1. ContentEntityForm::validateForm
  2. EntityForm::buildEntity
  3. ContetnEntityForm::copyFormValuesToEntity

Proposed solution

No working solution yet.

CommentFileSizeAuthor
#32 if_inline_entity_is-2611956-32.patch6.94 KBthenchev
#32 interdiff.txt1.69 KBthenchev
#28 interdiff-18-28.txt926 bytesaxe312
#28 2611956-28-ief_referenced_entity_validation.patch10.17 KBaxe312
#18 2611956-18-ief_referenced_entity_validation.patch10.15 KBaxe312
#18 2611956-18-ONLY-TEST-ief_referenced_entity_validation.patch4.08 KBaxe312
#16 if_inline_entity_is-2611956-16-TEST_ONLY.patch3.25 KBthenchev
#9 interdiff.txt3.73 KBslashrsm
#9 2611956_9.patch3.7 KBslashrsm
#6 2611956_entity_changes_timestamp_6.patch957 bytesmikgreen
#2 2611956_entity_changes_timestamp.patch886 bytesmikgreen
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikgreen created an issue. See original summary.

mikgreen’s picture

slashrsm’s picture

This seems like duplicate of #2609020: Unable to reedit entity in a single request. Can you check?

Status: Needs review » Needs work

The last submitted patch, 2: 2611956_entity_changes_timestamp.patch, failed testing.

mikgreen’s picture

Status: Needs work » Active

No, this happens with single entity. Unlike the other issue.
Also I tried latest dev with fix for other issue.
The problem is still there.

mikgreen’s picture

Just an update to match line numbers of current dev version.

slashrsm’s picture

Status: Active » Postponed (maintainer needs more info)

That other issue also happens with only one field. It was mentioned in a comment. Title was confusing. Fixed it.

Patch in that issue was committed. You can check if you still see this error with the latest HEAD.

axe312’s picture

Status: Postponed (maintainer needs more info) » Active

The error is not related to the other ticket, we have both issues in our project. First one is fixed, will now test this patch if it helps :)

slashrsm’s picture

Now I was able to reproduce. What about something like this? This patch removes all values that are not relevant for this specific IEF instead of just hardcoding one specific field name.

slashrsm’s picture

Issue tags: +Needs tests

I think we will also need some test coverage for this.

Status: Needs review » Needs work

The last submitted patch, 9: 2611956_9.patch, failed testing.

The last submitted patch, 9: 2611956_9.patch, failed testing.

slashrsm’s picture

+++ b/src/InlineEntityForm/EntityInlineEntityFormHandler.php
@@ -288,7 +290,15 @@ class EntityInlineEntityFormHandler implements InlineEntityFormHandlerInterface
+    $form_state_values = array_filter(
+      $form_state->getValues(),
+      function ($key) use ($parents) { return $key == $parents[0]; },
+      ARRAY_FILTER_USE_KEY
+    );

Third argument to array_filter is PHP 5.6 feature. Question is if we want to require 5.6 or not.

The last submitted patch, 9: 2611956_9.patch, failed testing.

slashrsm’s picture

Hm... I can't reproduce this any more. I noticed this bug in slightly different situation than the one described in the summary:

1. Create content type A
2. Create two media bundles B and C
3. Configure nested complex IEF (A => B => C) - both references are multivalue ER fields
4. Create content of type A, add one media B and add few C on it.
5. Try to edit one of C media items
6. Boom!

However, I can't reproduce it any more. I also can't reproduce with steps from issue summary. Can anybody else reliably recreate this error in isolation?

thenchev’s picture

Also can't reproduce issue. Here is a test only patch with the steps from the summary.

thenchev’s picture

Status: Needs work » Needs review
axe312’s picture

I was also no more able to reproduce since it is a lot of clicking, but I was still sure it may happen. The test of Denchev was missing the actual testing if the second edit attempt is working.

Here is a rewrite of the test, it is also now proving that the issue still exists. I also attached a working version of patch from #9, it is actually fixing the problem! :)

So let see what the test bot says!

axe312’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

The last submitted patch, 18: 2611956-18-ONLY-TEST-ief_referenced_entity_validation.patch, failed testing.

The last submitted patch, 18: 2611956-18-ONLY-TEST-ief_referenced_entity_validation.patch, failed testing.

The last submitted patch, 18: 2611956-18-ONLY-TEST-ief_referenced_entity_validation.patch, failed testing.

The last submitted patch, 18: 2611956-18-ONLY-TEST-ief_referenced_entity_validation.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 18: 2611956-18-ief_referenced_entity_validation.patch, failed testing.

The last submitted patch, 18: 2611956-18-ONLY-TEST-ief_referenced_entity_validation.patch, failed testing.

The last submitted patch, 18: 2611956-18-ief_referenced_entity_validation.patch, failed testing.

The last submitted patch, 18: 2611956-18-ief_referenced_entity_validation.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 28: 2611956-28-ief_referenced_entity_validation.patch, failed testing.

axe312’s picture

I am pretty sure it's all fine. The PostgreSQL test was failing for every patch here in the issue. Looks like an error in the test bot for me, does someone know more?

slashrsm’s picture

Yeah... Postgres test is failing quite often. I am pretty sure those fails are not related. I have just few cosmetic comments.

  1. +++ b/src/Tests/InlineEntityFormComplexWebTest.php
    @@ -325,20 +325,83 @@ class InlineEntityFormComplexWebTest extends WebTestBase {
    +   *
    +   * @see https://www.drupal.org/node/2611956
    +   */
    

    Do we really need to link the issue?

  2. +++ b/src/Tests/InlineEntityFormComplexWebTest.php
    @@ -325,20 +325,83 @@ class InlineEntityFormComplexWebTest extends WebTestBase {
    +    // Edit node to reference.
    

    "Edit referenced node."?

  3. +++ b/src/Tests/InlineEntityFormComplexWebTest.php
    @@ -325,20 +325,83 @@ class InlineEntityFormComplexWebTest extends WebTestBase {
    +    // Edit node to reference.
    

    "Edit referenced node."?

axe312’s picture

Changes of Denchev look good. Thx!

  • slashrsm committed e039a1e on 8.x-1.x authored by axe312
    Issue #2611956 by axe312, Denchev, mikgreen, slashrsm: If inline entity...
slashrsm’s picture

Status: Needs review » Fixed

I spoke with @bojanz and we agreed that we commit this and hopefully find a nicer solution later. It fixes a real problem which is enough for now.

Thank you everyone!

Status: Fixed » Closed (fixed)

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