We need to add clone support to entities (such as Nodes) that have other entities embedded within them, such as Paragraphs. We're focusing primarily on Paragraphs because Field Collection has been deprecated in favour of it. (See #2784931: Proposal: Deprecate Field Collections for Drupal 8, focus on Entity Reference Revisions & Paragraphs for details.)
This issue does not cover recursive entity nesting (i.e. entities within entities within entities etc.). Support for that will be handled by the follow-up #2913949: Add support for recursive cloning.
What remains to be done
Fix problem of cloned node deletions deleting original sub-entities (#52).Fix warnings and error on the clone form submission (#56).Figure out exactly what we're asking (and why) on the clone submission form (#56).Improve the UX on the clone form once it's clear what we're asking (see previous item).Make help text on clone form less technical and more understandable (#90).#2929336: Make help text on clone form less technical and more understandableMake sure translations are still working (#91).#2929334: Make sure translations are still workingEnsure clone form isn't showing up if disabled (#92).#2929338: Disable clone form for usersAdd test coverage for all of this (#59).
Original summary
Does the module support cloning e.g. a node that has paragraphs attached, and having the paragraphs entities cloned too rather than the new node pointing to the original paragraph entities?
Comment | File | Size | Author |
---|---|---|---|
#147 | interdiff-2706639_118_147.txt | 6.25 KB | vpeltot |
#147 | entity_clone-clone_sub_entities-2706639-147.patch | 50.69 KB | vpeltot |
#137 | Screen Shot 2018-03-14 at 10.31.07.png | 102.89 KB | sam.spinoy@gmail.com |
#131 | interdiff-2706639-127-130.txt | 564 bytes | pguillard |
#131 | entity_clone-clone_sub_entities-2706639-130.patch | 47.95 KB | pguillard |
|
Comments
Comment #2
vpeltot CreditAttribution: vpeltot commentedCurrently the clone for content entities is fully supported.
On the other hand, as you point out, all referenced entities (with entity reference fields) are simply attached and all target entities are not cloned.
I had already started this development.
Now, with this patch, in the clone form, a new checkbox has appeared to propose you a "recursive mode".
All referenced entities (except Files / Images / Taxonomy terms) are cloned too.
It should work with all entities including entities provided by the paragraphs module.
If you have time, can you test this patch ?
Comment #3
vpeltot CreditAttribution: vpeltot commentedComment #4
miro_dietikerPlease consider the Entity Reference Revision definition that is the underlying field storage of Paragraphs:
Entity Reference Revision defines a composite relationship and it is never allowed to have a target entity reused.
You don't need a setting for that, instead you are required to ALWAYS recurse on composite relationship entity reference revision fields.
This support makes sense as other modules consider building on top of ERR and we already have similar integration for this.
- The diff module will also recurse to show diffs on host entity.
- The TMGMT module makes sure the paragraphs are also passed to translation of a node / host entity.
- The collect module also embeds the paragraphs.
Complexity significantly goes down.
Happy to mark our ERR / Paragraph issue as fixed when ready... #2676226: Needs tests: Support cloning
Also i recommend to you to define recursing on entity references on a per-field level. Entity references are used in so many different ways:
From user reference, over term references, to related content references.
A general "recurse cloning" simply doesn't work semantically.
Comment #5
dpolant CreditAttribution: dpolant commentedI've supplied a simpler patch that just handles ERR fields. It does not offer a setting since like miro said, you always have to clone them.
There is also a bit in the patch to make it work with Multiversion.
Comment #8
DamienMcKennaTwo minor items:
Is there any need to create a local variable for this? Couldn't it just be used as-is in the if() statement?
Comments should not be written in the second person, it should be e.g. "If this is left in then Multiversion will not track revisions properly."
Comment #9
dpolant CreditAttribution: dpolant commentedHere is a better patch.
Comment #10
DamienMcKennaComment #11
DamienMcKennaComment #14
miro_dietikerHow about the status of multilingual support of this approach?
There's usually always more to consider with it than initially expected... ;-)
Comment #15
DamienMcKenna@miro_dietiker: I suspect we'll need some tests..
For the tests, should it e.g. start with a node that has translations and then clone it, or something else?
Comment #16
pogfra CreditAttribution: pogfra commentedHere a first draft patch based on that of the second comment.
It add checkboxes on clone form to choose which entity have to be clone.
It do not add support for entity clone revisions/dynamic entity references yet
Comment #17
ruloweb CreditAttribution: ruloweb commentedWhat if we add support to complex fields within an event?
I created a patch which dispatch some events before and after cloning #2800203: Event dispatcher for clone events.
Comment #18
ruloweb CreditAttribution: ruloweb at Media.Monks commentedAttached is a patch which depends on #2800203: Event dispatcher for clone events and implements recursives event subscribers to clone paragraphs and field collections.
I think this is a good approach because you just need to create an EventSubscriber class per each entity implementation, without the need to make changes on the existing files.
Cloning entity reference revisions is based on comment #2706639-9: Support for sub-entity cloning
I was able to clone entities like this one:
Comment #19
ruloweb CreditAttribution: ruloweb at Media.Monks commentedNew patch and its diff.
For field collections now it erases any previous values and then clone the new items. The last patch did that in the same foreach. It fixes some issues related to relations like Node -> Field Collection -> Paragraphs -> Field Collection.
Some typo fixed and deleted unnecessary functions.
Thanks!
Comment #20
RogerBTried #19 patch on a node with nested paragraphs. It did not work. Paragraphs are not being recursively cloned. The new node references the paragraphs of the original node. Edits to paragraphs of the clone appear in original.
Node structure:
Comment #21
ruloweb CreditAttribution: ruloweb at Media.Monks commented@RogerB did you clear cache? Events needs to be subscribed in order to works.
Comment #22
ruloweb CreditAttribution: ruloweb at Media.Monks commented@Rober and also you need to apply #2800203: Event dispatcher for clone events too, as I described in commit #18.
Comment #23
RogerBYes @ruloweb I later spotted that I had to add the #2800203: Event dispatcher for clone events patch as well. When I did it worked perfectly.
Comment #24
Kevin P Davison CreditAttribution: Kevin P Davison at Hook 42 for Go Overseas commented@RoberB are these patches still working for you on Drupal 8.2.3? I'm getting WSOD on /entity_clone/node/### with
Sequence:
Comment #25
weekbeforenextI added a condition to escape the onEntityCloned() method in FieldCollectionItem.php that tests to see if the 'field_collection_item' entity type exists. This fixes the error found in comment #24.
Comment #26
weekbeforenextHere is the patch.
Comment #28
Mars0test CreditAttribution: Mars0test at Alter Way for Klee Interactive (Klee Group) commentedThere are somethings missings, you call class who doesn't exist.
Comment #29
recrit CreditAttribution: recrit commented@BizuTétu: Both of those classes existed when I used the patches below. Note: The event subscriber patch #2800203: Event dispatcher for clone events is required for #2706639: Support for sub-entity cloning.
The following worked for me. I verified that the paragraphs on the clone node had new IDs.
Patches applied.
Comment #30
steel-track CreditAttribution: steel-track commentedI can also verify that with the three patches in #29 applied, cloning a node with paragraphs creates new paragraph entities. A cache clear was required for it to start working correctly.
Comment #31
bdanin CreditAttribution: bdanin commentedThe three patches as supplied in #29 appear to be working well for me too, thank you!
using 9265e35 specific dev version in composer:
"drupal/entity_clone": "1.x-dev#9265e35",
Comment #32
anairamzapComment #33
anairamzapComment #34
fabiansierra5191 CreditAttribution: fabiansierra5191 as a volunteer commentedThe tests were falling because they depend on other patches' issues.
These are related to the following patches:
I just applied the 3 patches of the comment #29 in the right order and cloning a node with multiple paragraphs, it created new paragraphs entities on Drupal 8.3.5 version.
Comment #35
rwam CreditAttribution: rwam commentedAfter losing a bunch of contents after deleting only one node I detect same problems. All affected nodes refer to the same field and field revision entries because they are clones of one original node and after deletion all still existing nodes refer to the fields and revisions which are deleted.
I've tested #29 resp. #34 and the three patches work for me as well. Cloned node creates new entries in field and field revision tables and a deletion is possible without affecting the original.
I've tested this in a multilingual environment on Drupal 8.3.5. with Paragraphs 8.x-1.1 and Entity Reference Revisions 8.x-1.3
Comment #36
vpeltot CreditAttribution: vpeltot commentedComment #38
michaellander CreditAttribution: michaellander at Elevated Third commentedI've updated the patch to reflect the changes from #2800203-10: Event dispatcher for clone events where the namespace
Drupal\entity_clone\Events
is changed to the singularDrupal\entity_clone\Event
.Comment #40
michaellander CreditAttribution: michaellander at Elevated Third commentedLooks like
EntityCloneEvents::PRE_SAVE
was renamed toEntityCloneEvents::PRE_CLONE
, and same withEntityCloneEvents::POST_SAVE
. Updated patch for that issue as well. See #2800203-10: Event dispatcher for clone events.Comment #41
colanFixed coding-standards violations and removed deep nesting.
Requires the patches from #2800203: Event dispatcher for clone events and #2908414: Error on abort and redirects - one patch to solve everything as prerequisites.
Didn't look too deeply into the failing tests, but I'm guessing that they're failing because the other patches haven't been applied yet. We should commit those, and then retest here.
Comment #44
vpeltot CreditAttribution: vpeltot commentedI just tested the last patch (in comment #41), but it doesn't work for me.
Step to reproduce:
Only the page is cloned.
The target of this issue is to clone recursively, with a choice (field by field), all referenced entities (
entity_reference
field type).In this patch, only
entity_reference_revisions
andfield_collection
field are supported.I think the best way to resolve this issue is re-rollling the #16 patch (that implement the correct way), and maybe include the
entity_reference_revisions
field type support.Comment #45
vpeltot CreditAttribution: vpeltot commentedReroll the patch in comment #16
Comment #46
vpeltot CreditAttribution: vpeltot commentedFix errors
Comment #47
vpeltot CreditAttribution: vpeltot commentedComment #48
vpeltot CreditAttribution: vpeltot commentedTests are now OK with the rerolled patch.
Now, from this patch, it remains to be done:
As for field_collection fields, why this module doesn't use an entity_reference or an entity_reference_revision fields?
Comment #49
colanAs per #2509254: Field collection fields should extend entity reference fields, it looks like Field Collection fields do extend Entity Reference fields in the third rewrite of the module (3.x). I can't find any reference to ERR over there.
Having said that, I think we should spend more time supporting Paragraphs/ERR and less time supporting Field Collection. After reading #2784931: Proposal: Deprecate Field Collections for Drupal 8, focus on Entity Reference Revisions & Paragraphs, I don't see too much continued effort going into Field Collection, especially when the following text is on the project page:
As far as this patch goes, I think we should get the above functionality in very soon, and create a new follow-up issue for recursion support. This way, we'll at least have basic cloning for these field types in alpha2, as planned. I've spun off #2913949: Add support for recursive cloning for that.
I should be able to review and test the above patch today, after which I'll either post another patch (if updates are required) or RTBC it. Barring any other major problems, we should be able to get this into Friday's release.
Comment #50
colanThe above patch works well. I just made some minor coding standards and style changes.
Comment #51
Mars0test CreditAttribution: Mars0test for Klee Interactive (Klee Group) commentedLooks good for me.
You need to use interface instead of class directly :
Comment #52
rwam CreditAttribution: rwam commentedI've tried #50 with latest dev release and it doesn't work as expected. All paragraph items of cloned and original node will be deleted if I delete the cloned or the original node. It's the same behavior like described on #35.
I have only paragraphs attached to a content type, no recursion. With the mentioned patches in #29 it works well.
So I have to do a rollback to my last working version.
Comment #53
vpeltot CreditAttribution: vpeltot commented@colan
I think it's better to support
entity_reference_revisions
field now.Many projects used the paragraphs module.
For the UX/UI improvement, I'm OK to postpone that
@rwam
The patch #50 does not allow the entity_reference_revisions field type to be cloned recursively.
Here a new patch.
Can you test this ?
Comment #54
vpeltot CreditAttribution: vpeltot commentedComment #55
rwam CreditAttribution: rwam commentedUps, cloning of node with paragraphs attached leads to:
Comment #56
colanI fixed that problem, but found some others. When I get checkboxes on the clone form (which I never got before), and don't select any, submitting the form leads to an error, with warnings leading up to it in the log:
From the backtrace, it looks like it's coming from
src/EntityClone/Content/ContentEntityCloneBase.php(99)
. This method is way too big to see what's going on. It needs to be broken into smaller ones as it is doing more than one thing. I'll see what I can do to fix.In other news, I think I can finally see the UX problem. I get a form with 2 checkboxes, which both say the same thing. The text says,
This raises some questions:
Comment #57
colanActually, I'll be out for part of the day so if someone else wants to pick this up, please do (and assign it to yourself first so we're not duplicating effort).
Comment #58
rwam CreditAttribution: rwam commentedSorry, the patch provided in #56 shows the same behavior: if I delete a cloned node, all paragraphs of the source node are missing/deleting too because of same field reference ;(
Comment #59
miro_dietikerYeah it's absolutely critical to test cover the delete case exactly as @rwam mentioned.
We had some similar custom code bug that caused so much pain because data is lost in context B while you act in context A. It took way too long to identify the issue and we couldn't simply revert the content DB anymore... Dangerous and painful.
Comment #60
colanI've updated the issue summary with everything that needs to be done. (Thanks for the feedback!) Please edit as necessary. We can strike out items after they're completed.
I'd really like help in understanding what we're asking for on the clone form as that's really not clear to me now.
Comment #61
colanComment #62
vpeltot CreditAttribution: vpeltot commentedComment #63
vpeltot CreditAttribution: vpeltot commentedThis patch contain:
* Refactor
* Little UI improvement
* New test to ensure referenced entities are cloned too
This patch works with
entity_reference_revisions
field types (used by paragraphs)For example :
1 node (eg. article):
- Body field
- Entity reference revisions field to paragraphs (type A & type B)
- Entity reference field to tags taxonomy term
2 paragraphs types:
- type A with a simple text field
- type B with an entity reference revisions to the type A paragraphs
Here the clone Form:
Comment #64
vpeltot CreditAttribution: vpeltot commentedComment #65
rwam CreditAttribution: rwam commentedFirst: thank you guys for working on this.
I've tested patch #63, but it doesn't work out of the box ;( And I have several issues with this new patch. Cloning of nodes with paragraph items works indeed but only if you understand the clone form correctly. I will try to demonstrate it with a screenshot. Here you can see a working form:
but wait:
One clicked option for cloning the user entity leads to:
Why should clone a user? That's strange. In my opinion the new clone form decrease the User Experience dramatically. Our editors use the clone functionality quite often. This form will lead to frustration to the user because of they will have no idea what options need to use. Best practice from my point of view: no options. My favoritized and working approach is still #35Comment #66
rwam CreditAttribution: rwam commentedComment #67
colanIt seems like we're trying to do too many things here. Here's a plan to get back to basics:
This has the benefit of:
I think it's safe to make assumptions about what types of entities to clone. Generally, we only want to clone entities that are tightly coupled with (and meaningless without) their host entities. For example, we do want to clone Paragraphs because they only exist in the host entity context, but we don't want to clone Users because they don't. Users exist on their own outside the referencing entity and have value in other contexts.
Even though Field Collections are another example of a tightly-coupled sub-entity, let's forget about them for now as they don't implement ERR and this makes it more complicated. This can be implemented in a separate follow-up issue. If there are use cases for cloning other types of sub-entities (those that aren't tightly coupled), these can be handled in other follow-up issues, and discussed there. Let's got a basic implementation of this working first so that we can cut another alpha release with it, and have something to build on.
Thoughts?
Comment #68
rwam CreditAttribution: rwam commentedHi @colan,
sounds good for me. And I'm ready to test further patches.
Ciao
Ralf
Comment #69
colan@vpeltot: What do you think?
Comment #70
mvantuch CreditAttribution: mvantuch as a volunteer commentedHi, we have recently faced the issue with paragraph references on two projects and your proposed solution (#67) would be exactly solving our problem.
Comment #71
vpeltot CreditAttribution: vpeltot commentedThis module provide a core to allows cloning any kind of entities.
The clone system, and specially for this issue "Support for sub-entity cloning", must be the same regardless of the target entity types attached on
entity_reference
(maybeentity_reference_revisions
) fields.Not all sites use paragraphs, not all sites use field collections, but ALL SITES use some entity reference fields.
We can't consider and handle all use cases with this module.
We must be (as must be any contrib module) as generic as possible.
To solve this issue and this discussion, and improve the UX, what do you think about:
To handle all other uses cases, this module add two handler in entities:
entity_clone
entity_clone_form
Everyone can be create their own handler classes for custom entities or override all existing handler classes.
Comment #72
colanIf by this you mean that there's a configuration option to skip the clone form (a checkbox like Allow users to specify sub-entity cloning behaviour that can be left unchecked), and just use the defaults, I think this is a good solution which (1) can provide a good UX (i.e. no clone form), and (2) allows for clone workflow flexibility. This should satisfy all of the feedback we've received so far.
Comment #73
colan@vpeltot: Do you have time to work on this? If not, I can work on it in the next couple of weeks.
Comment #74
vpeltot CreditAttribution: vpeltot commented@colan, thanks for your help, but I started this feature since some days.
Here a first patch with new settings form
/admin/config/system/entity-clone
to define the entity clone form settings.This form allows to set (for referenced entities in the entity clone form regarding the target entity type):
@colan, Can you test this patch? And maybe refine:
Comment #76
vpeltot CreditAttribution: vpeltot commentedFix tests errors
Comment #78
vpeltot CreditAttribution: vpeltot commentedFix settings manager class name in service file.
Comment #79
colanYes, will test shortly. Thanks for working on this. I found some coding standards issues so fixing that and breaking up some of the big methods first.
Comment #80
colanHere's the code clean-up. I didn't get a chance to test it yet, but I will shortly.
Comment #82
colanNoticed this failed so unassigning in case someone wants to take a look while I'm off for the day.
Comment #83
vpeltot CreditAttribution: vpeltot commentedNew patch with:
Comment #84
rwam CreditAttribution: rwam commentedHm, the patch works only for the following settings:
- CHECKBOXES DEFAULT VALUE – checked
– DISABLE CHECKBOXES – not checked
- HIDE CHECKBOXES – not checked
If either »DISABLE CHECKBOXES« or »HIDE CHECKBOXES« are checked, cloning doesn't clone referenced entities. And deleting a cloned node will delete all paragraphs. And all affected nodes have missing references ;-(
The problem is situated in the cloning form. If you disable or hide the checkboxes, the default value setting is not considered by the cloning form.
I want to have the following settings to work:
- CHECKBOXES DEFAULT VALUE – checked
– DISABLE CHECKBOXES – not checked
- HIDE CHECKBOXES – checked
The editor gets an well known interface (not checkboxes) and cloning works for referenced entities too.
Comment #85
colanHere's the last interdiff.
@vpeltot: The code looks a lot better now, which is great. Thanks for switching to
::class
everywhere inentity_clone.module
. That was the next step. I still thinkContentEntityCloneBase::cloneReferencedEntities()
is too long. Methods shouldn't be longer than 20 lines or so, unless they're producing a big form or some such. That's why I broke outgetChildProperties()
andgetTargetIds()
. Maybe these could use better names, but is there a reason we can't do something like this? It would make the code much more readable.That aside, I'll start looking at functionality.
@rwam: Thanks for the extremely quick reviews!
Comment #86
colanWhat I've found so far UX-wise:
$form['description'] = ['#markup' => 'Form description here'];
. Needs to be done for both:We can worry about the above items later; I'm happy to get this thing working first.
Functionally, on running the clone operation with Paragraph fields, I wasn't getting new entities (even though it looked like I was as I could change the clone's values without it affecting the original). As mentioned above, deleting the clone would delete the original's values.
I believe I found the problem over here:
Dropping the
===1
seems to work better as the value is probably a string and not an integer (having come from the form submission). When I delete the clone, the original's values are still there. Can someone else confirm?Comment #87
websiteworkspace CreditAttribution: websiteworkspace commentedThe ability to clone sub-entities, (entities within entities), is essential to be able to support cloning of Drupal Commerce 2.x entities. A Commerce entity always consists of a product entity with at least one product variation entities embedded, in which there can also be product attribute entities embedded within the product variation.
Currently, entity clone cannot correctly clone a Commerce 2.x entity.
Comment #88
rwam CreditAttribution: rwam commentedIt seems to work better, right. But I think there are more tests necessary, because it was a quick test and for paragraphs only.
Comment #89
colanThis should fix all of #85 and #86. Please test.
Comment #90
rwam CreditAttribution: rwam commentedHi @colan,
settings in combination with hidden checkboxes work well, but the following setting results in the same error of corrupt clone with not cloned sub entities:
- CHECKBOXES DEFAULT VALUE – checked
– DISABLE CHECKBOXES – checked
- HIDE CHECKBOXES – not checked
By the way: I'm undecided because of the amount of text on the clone form page. It's also too technical from my side. Which content editor knows all kind of build in terms. Especially if all options are hidden this could lead to some frustrations to the editor. Any other thoughts to this topic are appreciated.
Ciao
Ralf
Comment #91
Johnny vd Laar CreditAttribution: Johnny vd Laar at ezCompany commentedThe patch works for me on a paragraph with a nested paragraph. But it's not working on the translation.
So my node:
node:
- paragraph
-- paragraph
has a translation NL & EN
The EN translation has correct new nested paragraphs. The NL has an incorrect lowest level paragraph (still the original). It also didn't change the NL node title with the clone suffix.
Comment #92
achtonI can confirm the bug in #86 re. "deleting the clone would delete the original's values", even with the latest patch.
I am working with a Paragraph field with multiple paragraphs, and while it appears that editing the original's paragraphs does not affect the cloned node, deleting the original node will delete the paragraphs in the new, cloned node.
Also, I was unable to hide the form shown when clicking the Clone menu item, regardless of the configuration of the module - is it forced shown for admin users?
Comment #93
andypostProbably better to split the huge patch in parts, it has a lot of code style changes (array syntax & @file)
Comment #94
miro_dietikerHmm, stumbled across this and i have to admit that my wordings in #2706639-4: Support for sub-entity cloning was not fully correct.
ERR only is a forced composite relationship if it is annotated as such. (For instance Paragraphs annotates the fields that ERR can use as a parent reference).
If you use ERR without that annotation, it can be used to point to any revision of a non-composite entity and that case should be treated like regular ER. Side note: The ERR does not offer a widget at all that allows a user to see that the reference points to an outdated revision and neither offers tools to update that reference. This functionality could make sense for demanding legally strongly moderated content situations, but needs further investigation and support.
I think it's fine to focus on a simplified implementation and support the extra use-case in follow-ups.
Comment #95
vpeltot CreditAttribution: vpeltot commented@rwam
I tried to reproduce your use case, but I don't
My test, step by step:
Configuration:
Paragraphs type A
Paragraphs type B
Create contents:
Paragraph A
Paragraph B
Clone:
After clone:
Article test
Article test (Cloned)
First article is always the same and paragraphs still the same too
Cloned article and their paragraphs have the 'Cloned' values
Comment #96
rwam CreditAttribution: rwam commentedHi @vpeltot,
that's right, the revisions are different, but the entity id is the same. There is one more step missing:
Delete content:
All paragraphs are missing on the original too.
Ciao
Ralf
Comment #97
vpeltot CreditAttribution: vpeltot commented@rwam
Yeah ! I have reproduced your (last?) bug !
The cause was: When a form element is disabled, the
#default_value
is ignore in$form_state->getValues()
.I've replace:
'#default_value' => $this->entityCloneSettingsManager->getDefaultValue($referenced_entity->getEntityTypeId()),
by
'#value' => $this->entityCloneSettingsManager->getDefaultValue($referenced_entity->getEntityTypeId()),
Here a new patch with:
Comment #99
vpeltot CreditAttribution: vpeltot commentedwithout
kint()
calls ... :-)Comment #101
rwam CreditAttribution: rwam commentedHi @vpeltot,
Yeah ! I have reproduced your (last?) bug !
May be, we'll see ;)
I've tested your patch in #99 and it works fine. Cloning nodes with paragraphs and with disabled or hidden checkboxes (described in #84) creates new entities resp. revisions and it's possible to delete original or cloned content without losing any other content.
I think, other tests are necessary (Commerce, Media, Blocks), but it looks pretty good so far.
Thank you and ciao
Ralf
Comment #102
vpeltot CreditAttribution: vpeltot commentedComment #103
colanAttached is an interdiff for easier code review between my last patch, and the last one here which fixes the deletion issue, the failing test, and some coding standards.
I've updated the list of things to do / test in the IS based on recent comments.
Can folks test to ensure that the data loss problem is fixed? If so, maybe we can commit this, and then get everything else done in follow-up issues. This issue is getting rather long and complex.
Comment #104
vpeltot CreditAttribution: vpeltot commentedLet's end with this issue.
I've created a new issues for less critical todo:
Remaining tasks:
Comment #105
vpeltot CreditAttribution: vpeltot commentedAdd test assertions:
Comment #106
vpeltot CreditAttribution: vpeltot commentedTests OK, no more remains to be done.
Comment #107
john.oltman CreditAttribution: john.oltman commentedSuccessfully tested on 8.4.3 with deeply nested Paragraphs. However, when the content has a Paragraph that references a Menu via an Entity Reference field on the Paragraph Type, the following error is thrown immediately after the Clone link is clicked:
Recoverable fatal error: Argument 1 passed to Drupal\entity_clone\EntityClone\Content\ContentEntityCloneFormBase::getChildren() must implement interface Drupal\Core\Entity\ContentEntityInterface, instance of Drupal\system\Entity\Menu given.
This is certainly a less common use case, but since Paragraphs can reference entities that aren't content, probably worth fixing at some point. FWIW, I am using the menu_reference_render module to output the referenced menu entity, although that isn't coming into play during the clone.
Comment #108
DamienMcKennaWould this help, verify that the $referenced_entity is a ContentEntityInterface before processing it?
Comment #109
larowlanAdded related issue
Comment #110
larowlan#2933820: Consider changing clone handlers to use core's entity duplication API would enable us to take advantage of paragraph module's existing deep-cloning support
Comment #111
larowlannit, should use third argument, as we know these are strings
can just use
!empty()
herein theory, this shouldn't be needed. The
setValue
call with an entity object should handle this for you at the typed data layer. i.e. you should be able to set the value using the entity objects. See http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/Field/Plugin... and http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/Field/Plugin...These should typehint interfaces, not concrete classes
what about base fields? it is possible to define an entity reference field or paragraph field as a base field, using FieldConfigInterface we're limiting our options
this should include an access check,
'#access' => $referenced_entity->access('view label'),
is this needed?
Removed the related issue, I missed the fact that the form already called that.
Comment #112
larowlanAlso, there are a lot of coding standards changes in the patch.
In my opinion, to minimize the disruption and size of the patch, those should be split into their own issue.
Comment #113
larowlanE.g, this patch conflicts with #2845094: Batch field creation but only because of the coding standards changes
Comment #114
larowlanThis should be hidden if all checkboxes are also hidden.
See screenshot
Comment #115
larowlanmissing leading \
Missing @return tag
Comment #116
larowlanFixes #114
Comment #117
larowlanthis also needs an update hook to create the new config object and clear the cache, to setup the entity_clone_form handlers on the entity types
Comment #118
vpeltot CreditAttribution: vpeltot commented@larowlan Thanks for this review.
In this patch:
#111
\Drupal\entity_clone\Form\EntityCloneForm::submitForm
to get form values from specific form handlers#115
Done
#116
Included with rework. Description and method
descriptionShouldBeShown
moved in\Drupal\entity_clone\EntityClone\Content\ContentEntityCloneFormBase
#117
Done
Comment #119
pguillard CreditAttribution: pguillard commentedThanks for this patch ! RTBC ++
Just corrected 3 typos (some trailing whitespace when applying the patch..)
I guess some english natives should verify the form description.
At least I suggest this one :
=>
Comment #121
pguillard CreditAttribution: pguillard commentedComment #122
pguillard CreditAttribution: pguillard commentedI guess the 2 failing tests are not related to this patch, but also failing also on the 8.x-1.x branch !
Can't find why..
Comment #123
sam.spinoy@gmail.com CreditAttribution: sam.spinoy@gmail.com at Adapt commentedAwesome work here with this patch! Been testing it on a site that has lots of content and references, and I regularly run into this error:
This happens when a reference field contains a target_id that points to an entity that has been deleted. I've added a new patch based on the previous one, where we simply skip the deleted entity instead of trying to load/clone it.
Comment #124
colan#123: Please provide an interdiff.
Comment #125
pguillard CreditAttribution: pguillard commentedAttached an interdiff for the last patch #123.
Comment #127
pguillard CreditAttribution: pguillard commentedSome
.DS_Store
stuff was introduced in #123, so this is a new patchComment #129
amy.h CreditAttribution: amy.h commentedDoes this support cloning panels pages? Along with the variants and block plugins inside it.
Comment #130
DamienMcKenna@matthew.h: I believe Panels pages are config entities, and this module works on content entities, so that'd be "no".
Comment #131
pguillard CreditAttribution: pguillard commentedThis new one should pass tests.
I guess this is the change : Issue #2911806: Remove unnecessary Crypt::hashBase64() call from Action UI by tim.plunkett.
This is impacting the whole module, not this patch particulary.
(I made another ticket there #2950432: EntityCloneActionTest fails)
Comment #132
sam.spinoy@gmail.com CreditAttribution: sam.spinoy@gmail.com at Adapt commentedIn relation to this ticket https://www.drupal.org/project/entity_clone/issues/2945192
I noticed that all form elements in the formElement() method in the ContentEntityCloneFormBase class get built no matter what, even if the user has no access to them (because the "Hide checkboxes" option is checked at /admin/config/system/entity-clone). I've made an addition to the patch that simply skips the fields if we cannot access them.
This does not actually solve the problem of the timeout in #2945192 due to recursive looping, but it does offer a workaround: if an admin decides how to clone entities (and thus checks all the "Hide checkboxes" on the config page), we don't need to build a render array and get no error.
Again, I know it doesn't actually solve the problem but I think it's a good addition either way, no need to build stuff that will not be rendered anyway. The cloning actions seems to be successful without this "invisible" form too, though that might be because of my specific setup. I'm sure one of the module maintainers will have a more qualified opinion on this :)
Comment #133
colan#132: Please provide an interdiff so we can more easily review changes. Thanks.
Comment #134
pguillard CreditAttribution: pguillard commentedInterdiff
Comment #135
sam.spinoy@gmail.com CreditAttribution: sam.spinoy@gmail.com at Adapt commentedActually that latest change of mine makes it so that sub-entities don't get cloned :/ The cloned node just refers to the same entities as the original page. So please disregard the patch.
Comment #136
sam.spinoy@gmail.com CreditAttribution: sam.spinoy@gmail.com at Adapt commentedComment #137
sam.spinoy@gmail.com CreditAttribution: sam.spinoy@gmail.com at Adapt commentedI guess the problem for issue 2945192 lies in the fact that recursive cloning can get quite complicated depending on your setup. Looking at the image below you can see that I'm already 5 levels deep, and that is just from one node referencing a paragraph that than in turn references another node that has another paragraph, ...
I am thinking that not displaying anything below the first unchecked checkbox by default could help, and when a user checks the "yes let me clone this entity" checkbox, ajax in the sub-elements? It would in any case avoid the rending of a huge form with a lot of nested elements from the beginning.
For the project that I'm working on now I've created a patch that does not display any sub-elements if the parent type shouldn't be cloned. It works for me because the editors have no control over what they can clone or not, so all the checkboxes are hidden by default. This is not a generic solution though.
Comment #139
colan#137: Please create a follow-up issue for that.
Comment #140
sam.spinoy@gmail.com CreditAttribution: sam.spinoy@gmail.com at Adapt commentedA follow-up issue on what? There is already an issue here https://www.drupal.org/project/entity_clone/issues/2945192 but I figured I'd keep it all in one thread since it's about the same functionality.
Comment #141
colanI was talking about this UX issue you raised:
My point was that we should focus exclusively on getting the primary goal here finalized and committed. UX improvements and the like can be handled afterwards, in separate issues. If we try to do too much in this issue, we'll never get it done. As can be seen in #2945192: Fatal error: Maximum function nesting level of '256' reached, aborting! With Support for sub-entity cloning patch, a lot of folks are waiting for this.
Comment #142
sam.spinoy@gmail.com CreditAttribution: sam.spinoy@gmail.com at Adapt commentedI agree, but I don't think the ajaxing in of sub-elements is a UX improvement, I saw it as a way of solving issue #2945192. But it might not be the best way, I don't know.
Comment #143
pguillard CreditAttribution: pguillard commentedI added another follow-up issue/proposition : #2953641: Possibility to set fields that should not be cloned
Comment #144
pguillard CreditAttribution: pguillard commentedPatch at #137 needs some extra work on the EntityCloneContentRecursiveTest.
A schema for our entity_clone form_settings was also missing.
Comment #145
Pejka CreditAttribution: Pejka as a volunteer commentedThis patch can not be applied to alpha2 version
Comment #146
pguillard CreditAttribution: pguillard commentedYou should try it on the 8.x-1.x-dev branch
Comment #147
vpeltot CreditAttribution: vpeltot at Niji commented#129 / #130
@matthew.h @DamienMcKenna This module supports to clone config entities, and provide a clone base / core concept for all drupal core entities.
If an entity (like panels & co) doesn't supported by this module, I suggest to create modules for each specificities (eg. entity_clone_panels)
#132 / #137 / ...
All problems around #2945192: Fatal error: Maximum function nesting level of '256' reached, aborting! With Support for sub-entity cloning patch must be discussed / resolved in #2945192: Fatal error: Maximum function nesting level of '256' reached, aborting! With Support for sub-entity cloning patch
This new patch has been created from #118 and contains all @pguillard updates. All updates about #2945192: Fatal error: Maximum function nesting level of '256' reached, aborting! With Support for sub-entity cloning patch was removed.
Comment #148
volegerAt least patch helps to clone paragraph references correctly.
I had added the checkbox for paragraphs entity references, and now deletion of the cloned entity has no influence on the references of the original entity.
Comment #149
Mars0test CreditAttribution: Mars0test at Niji commentedOk it's fine for me.
For a next feature improve the ux can be great. ;)
Comment #151
vpeltot CreditAttribution: vpeltot at Niji commentedCommited !
Thanks @all
Comment #152
pguillard CreditAttribution: pguillard commentedCool, thanks !
Comment #153
rwam CreditAttribution: rwam commentedGreat news. Thanks @all.
Comment #154
hudriThanks a lot for all the work done here, the editors in my office are really keen on this patch, will save them a lot of time. Could we get a new release for this in the alpha channel?
Comment #156
jibranJust saw this commit in latest dev I think we should address these before next release.
Desc should be a summary of what this update is performing.
This should be post-update hook.
Comment #157
colanCan you repost in #2930403: [META] Beta1 release? This issue is closed/fixed.
Comment #158
acbramley CreditAttribution: acbramley at PreviousNext for University of Adelaide commentedOpened a follow up for #156 #3008195: Move update hook to post update hook
Comment #159
websiteworkspace CreditAttribution: websiteworkspace commentedThanks for working on this problem.
I am putting this code update on my todo list for regression testing on a test site, to see if this works properly now with custom content types that contain paragraphs, and with drupal commerce 2.x products and so forth which also contain nested entities.
-
Also, when will those code change make its way into an alpha/beta release and not just in the dev channel release?
Comment #160
Chris Matthews CreditAttribution: Chris Matthews commented