- last update
over 1 year ago 29 pass - 🇬🇧United Kingdom jonathanshaw Stroud, UK
However you do it, I think this work is untangling work is important and I will try to support it with reviews.
- 🇧🇪Belgium dieterholvoet Brussels
I'm getting a bit tired of rebasing this one, with every commit to the dev branch it's so much work. I hope we can get this one in soon, or I'll probably just stop updating entity_clone on my sites.
- 🇧🇪Belgium dieterholvoet Brussels
I squashed all commits to the issue fork to make it easier to rebase this one. For the same reason, I also undid some code style related changes. This one applies to 2.x again.
- Status changed to Needs work
5 months ago 3:54am 9 July 2024 - 🇮🇳India ankitv18
Along with fixing phpunit failure, please check this also:https://git.drupalcode.org/issue/entity_clone-2965701/-/jobs/2021834#L47
- Status changed to Needs review
5 months ago 8:58am 9 July 2024 - 🇺🇸United States partdigital
FWIW on our project we had to build an entity duplication service. We were originally using entity_clone but had to refactor the work because, unfortunately, entity_clone was not quite flexible enough. We ended up creating our own API which made it very flexible to define a duplication task. I’m happy to contribute in this (or another issue) if anyone is interested. (Note that we also have test coverage).
To summarize these are the parts of our API.
DuplicationStrategy
This defines how we want our duplication to run. This is where we define which fields, entity types, bundles and even individual entities we want to include in the duplication process.DuplicationProcess
This generates duplication process based on the entity and strategy that is passed to it. It essentially generates an array that details every step that needs to happen for successful duplication. We’ve used to this diagnose any issues before the duplication actually happens.DuplicationExecutable
This actually executes the duplication process. It does this by reading the duplication process array and executing each step along the way. Because the duplication process is an array it’s very easy to perform it as a batch.Some remaining work:
We need to add a way to undo/rollback the duplication process if there is an error. Doing it in a single request it’s very easy but doing it as a batch can be a bit trickier.Here is an example of the API:
<?php
// This defines a strategy that will duplicate nodes found in the “related_content” field but will exclude articles.
$strategy = DuplicationStrategy::create($entity);
$strategy->setEntityTypes(['node']);
$strategy->addField(‘related_content’);
$strategy->excludeBundles([‘article’]);// Pass the strategy to DuplicationProcess object. This will generate the array of all necessary steps.
$process = new DuplicationProcess($entity, $strategy);
$process->build();// Pass the process to the executable. This will execute all the steps in the process and return the duplicated entity.
$executable = new DuplicationExecutable($process);
$executable->execute();
return $executable->getDuplicate();Just food for thought :D
- Status changed to Needs work
3 months ago 8:45am 26 August 2024 - 🇧🇪Belgium joevagyok
@partdigital can we have another PR with your proposal in a different branch on this issue for us to evaluate and choose?