Problem/Motivation

In D7, cloning a paragraphed node led to data loss #2394313: Paragraphs data loss with Node Clone module
That's because the paragraphs are then shared...

In D8 that's not possible anymore with the new entity reference revisions (ERR) composite relationship.
However, we need to make sure that a cloned node does not steal the paragraphs (forcing an update of the parent relationship.)
And we know from other issues, that the save currently happens in the paragraphs widget and not bound the host entity save as a whole
#2676098: Do not save in widget

Proposed resolution

Identify scenarios to clone a host entity and test cover them to make sure we support them properly.
Fix them if there's inconsistency.

There might be some elements on composite reassignment that should be handled in ERR.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#49 2676226_49_test_only.patch7.73 KBslashrsm
#41 interdiff.txt652 bytesslashrsm
#41 2676226_41.patch3.44 KBslashrsm
#38 2676226_38.patch3.46 KBslashrsm
#38 2676226_38.patch3.46 KBslashrsm
#28 2676226_requires.patch477 bytesslashrsm
#26 2676226_26.patch7.73 KBslashrsm
#22 2676226_fix_tests.patch2.29 KBslashrsm
#18 paragraphs_2676226_cloning_test_18.patch7.97 KBmiro_dietiker
#17 2676226_test_dependency.patch244 bytesslashrsm
#11 2676226_11.patch9.83 KBslashrsm
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

miro_dietiker created an issue. See original summary.

Berdir’s picture

I'm not sure if a field currently can even act on a clone. createDuplicate certainly doesn't invoke a method on fields.

node_clone might add a hook but then it only works with that.

miro_dietiker’s picture

Hm yeah, we need to support cloning in the most common D8 way, like node clone was at least for D7.
If node clone will be stabilised again, then it should be this. However i think naming is bad since it should cover any entity.

I recently heard about an alternative / better approach, but can't find it anymore...
BTW also how about replicate? https://www.drupal.org/project/replicate

Berdir’s picture

Whatever we want to support is fine with me, just saying that the core API alone won't help us get there. I see @dawehner did a replicate D8 port. afaik node_clone is being worked on too.

miro_dietiker’s picture

We can also wait a bit until things settle down and we have a first real use case or someone contributing integration because they need it.

DamienMcKenna’s picture

Definitely interested to see these working together for a site I'll theoretically be working on soon-ish, hopefully I (or a coworker) will be able to help out make it work.

DamienMcKenna’s picture

DamienMcKenna’s picture

FYI there's WIP for a D8 port of Node Clone, and there's the newer Entity Clone module that has dev version available for it.

miro_dietiker’s picture

IMHO cloning integration would be provided by Entity References Revision module.

miro_dietiker’s picture

BTW both Collect and TMGMT have code ready to steal for selecting a field to recurse Entity References..

slashrsm’s picture

Attached patch provides integration with Replicate module. Test will fail since the D8 port was not pushed to the drupal.org yet, but it passes locally.

Status: Needs review » Needs work

The last submitted patch, 11: 2676226_11.patch, failed testing.

The last submitted patch, 11: 2676226_11.patch, failed testing.

The last submitted patch, 11: 2676226_11.patch, failed testing.

DamienMcKenna’s picture

The tests will also fail because it can't find the Replicate module. In D7 you could just add a test_dependency[]= line to the info file, is that possible with D8?

miro_dietiker’s picture

Yeah. Plz provide a test dependency patch only first so i can commit it.

slashrsm’s picture

miro_dietiker’s picture

Ha! test-only doesn't really help if it's not on d.o. ;-D

Still committing, with keeping test coverage uncommitted to avoid fails until replicate is on d.o.
Attached remaining test incl. test dependency.

miro_dietiker’s picture

Title: Support cloning » Needs tests: Support cloning
Issue tags: +Needs tests
miro_dietiker’s picture

Priority: Normal » Critical

Oopsie, head broken. We accidentally introduced a hard dependency to the replicate module.
The service needs to be defined conditionally, with the optional dependency.

slashrsm’s picture

This should fix the tests. Also confirmed uncommitted Replicate test is still passing.

  • miro_dietiker committed 274dc04 on 8.x-1.x authored by slashrsm
    Issue #2676226 by slashrsm, miro_dietiker: Needs tests: Support cloning...
miro_dietiker’s picture

Priority: Critical » Normal
Status: Needs review » Needs work

Committed fix for HEAD.

Back to needs work for the tests.

miro_dietiker’s picture

Priority: Normal » Critical

Dear friend, why are you still failing!

slashrsm’s picture

Replicate integration test somehow sneaked into the commit.

Berdir’s picture

Can we try what the commit suggests? (@requires module replicate annotation) If that works, then it will automatically start to work as soon as replicate is on d.o.

And it will also not fail locally when running all tests and you don't have that module.

Not sure if it will work, I think it's still broken with simpletest but maybe it works with phpunit...

slashrsm’s picture

Tried locally and it failed both with run-tests.sh and phpunit. Does patch look correct?

Status: Needs review » Needs work

The last submitted patch, 28: 2676226_requires.patch, failed testing.

  • miro_dietiker committed 19fcc95 on 8.x-1.x authored by slashrsm
    Issue #2676226 by slashrsm, miro_dietiker: Needs tests: Support cloning...
miro_dietiker’s picture

Priority: Critical » Normal

Committed the test removal. I accidentally committed them after adding to staging in #18... Sorry! :-)

Back for resolving the tests situation...

The last submitted patch, 22: 2676226_fix_tests.patch, failed testing.

The last submitted patch, 26: 2676226_26.patch, failed testing.

The last submitted patch, 28: 2676226_requires.patch, failed testing.

The last submitted patch, 22: 2676226_fix_tests.patch, failed testing.

The last submitted patch, 26: 2676226_26.patch, failed testing.

The last submitted patch, 28: 2676226_requires.patch, failed testing.

slashrsm’s picture

Discussed this with @Berdir and he suggested slightly different approach. This does look much nicer indeed.

slashrsm’s picture

Berdir’s picture

+++ b/src/ParagraphsServiceProvider.php
@@ -0,0 +1,31 @@
+    $modules = $container->getParameter('container.modules');
+    // Check for installed REST & HAL modules, as HAL requires REST.
+    if (isset($modules['replicate']) ) {

:)

slashrsm’s picture

Berdir’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Now it looks fine to me.

The last submitted patch, 18: paragraphs_2676226_cloning_test_18.patch, failed testing.

The last submitted patch, 18: paragraphs_2676226_cloning_test_18.patch, failed testing.

The last submitted patch, 18: paragraphs_2676226_cloning_test_18.patch, failed testing.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Committed. :-)

  • miro_dietiker committed 97ff015 on 8.x-1.x authored by slashrsm
    Issue #2676226 by slashrsm, miro_dietiker, Berdir: Needs tests: Support...
Berdir’s picture

Status: Fixed » Active

We will still need to commit the test ;)

slashrsm’s picture

Status: Needs review » Needs work

The last submitted patch, 49: 2676226_49_test_only.patch, failed testing.

The last submitted patch, 49: 2676226_49_test_only.patch, failed testing.

The last submitted patch, 49: 2676226_49_test_only.patch, failed testing.

miro_dietiker’s picture

Status: Needs work » Postponed

Hm, isn't postponed the best fitting state?

slashrsm’s picture

Status: Postponed » Needs work

Replicate has been pushed to d.o.

The last submitted patch, 49: 2676226_49_test_only.patch, failed testing.

The last submitted patch, 49: 2676226_49_test_only.patch, failed testing.

The last submitted patch, 49: 2676226_49_test_only.patch, failed testing.

The last submitted patch, 49: 2676226_49_test_only.patch, failed testing.

The last submitted patch, 49: 2676226_49_test_only.patch, failed testing.

The last submitted patch, 49: 2676226_49_test_only.patch, failed testing.

miro_dietiker’s picture

Yay, awesome! Sooo, what's wrong here? :-)

Berdir’s picture

Search api broken, I think we have to wait on the next release, monitoring also has search api test fails.

Berdir’s picture

Status: Needs work » Needs review

The new test is passing, so it's not a problem with this issue. Didn't really review, so just needs review, not RTBC.

slashrsm’s picture

Yup, tests failed on HEAD, which proves #62.

miro_dietiker’s picture

Status: Needs review » Fixed

Test reads much nice. Happy to commit! :-)

  • miro_dietiker committed 19fea2d on 8.x-1.x authored by slashrsm
    Issue #2676226 by slashrsm, miro_dietiker, Berdir: Needs tests: Support...

Status: Fixed » Closed (fixed)

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