Problem/Motivation

In case of an entity with an entity reference field containing the entity itself, the entity is cloned three times.

Step to reproduce

With standard installation:

  • Add an entity reference field to the article content type
  • Create a new article
  • Save
  • Edit the article
  • Reference the article itself in the entity reference field
  • Save
  • Clone

The content is cloned three times:

  • 2 with "- cloned" label
  • 1 without "- cloned" label

Comments

vpeltot created an issue. See original summary.

vpeltot’s picture

Status: Active » Needs review
StatusFileSize
new11.25 KB

Here a patch to solve this.

  • Refine the form to add information in case of reference circular is detected
  • Force to use already cloned entity when an entity has a circular reference

Status: Needs review » Needs work

The last submitted patch, 2: 3030806-2-entity-with-direct-circular-reference-is-cloned-three-times.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

vpeltot’s picture

Status: Needs work » Needs review
StatusFileSize
new15.71 KB
new9.61 KB

Status: Needs review » Needs work

The last submitted patch, 4: 3030806-4-entity-with-direct-circular-reference-is-cloned-three-times.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

vpeltot’s picture

Status: Needs work » Needs review
StatusFileSize
new15.45 KB
new9.35 KB

Status: Needs review » Needs work

The last submitted patch, 6: 3030806-6-entity-with-direct-circular-reference-is-cloned-three-times.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

vpeltot’s picture

Status: Needs work » Needs review
StatusFileSize
new15.52 KB
new9.42 KB
vpeltot’s picture

Add tests to cover this issue.

vpeltot’s picture

vpeltot’s picture

The same patch with coding standards issues fixed.

mars0test’s picture

RTBC
After testing all seems good for me !

mars0test’s picture

Status: Needs review » Reviewed & tested by the community

  • vpeltot committed 3104669 on 8.x-1.x
    Issue #3030806 by vpeltot: Entity with direct circular reference is...
vpeltot’s picture

Status: Reviewed & tested by the community » Fixed

Commited !

Status: Fixed » Closed (fixed)

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

dksdev01’s picture

Looks after this change, hook_entity_presave is being called twice on every clone. thanks

akalam’s picture

This change is also causing a unneeded redirect whenever you clone a node if you have installed the redirect module and configured in "automatic" mode.

Is really needed to save the cloned entity twice? Maybe we can add the cloned entity to the $already_cloned as a reference.

vishnutrz’s picture

When we have entity clone module and redirect module with "Automatically create redirects when URL aliases are changed" enable. We can see unwanted redirect create when clone the node due to update in the label "- cloned" on save the entity second time.

We can avoid this by change the label at initial entity save itself.

Attached is a simple patch that fixes this.