Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
i need a "Duplicate" button, so i can create new variation with the same images (i don't have to upload the images again)
see the attachment!
Comment | File | Size | Author |
---|---|---|---|
#77 | 1590146-77-duplicate-entity-d8-beta1.patch | 9.12 KB | ilya.no |
#77 | 1590146-77-duplicate-entity-d8-dev.patch | 9.12 KB | ilya.no |
#60 | 1590146-60-clone-entity.patch | 11.08 KB | bojanz |
#53 | ief_clone_button-1590146-53.patch | 10.64 KB | danreb |
#51 | ief_clone_button-1590146-51.patch | 10.64 KB | danreb |
Comments
Comment #1
leanderl CreditAttribution: leanderl commentedFirst: thank you to the guys who did this great module. It completely changes the usability of commerce and has made me (and hopefully soon my client) very happy.
A clone button is sorely needed. It is the number one request I hear from all editor users.
And perhaps after that a really smooth solution for adding existing product entities (other than SKU). Somehting similar to choosing images with Media Modules Media Library -- browsing product entities a selecting which ones should be included. Then again perhaps that should be compartmentalized into a submodule of IEF.
This is a clone button that works for my project that I did together with OlleOlleOlle. Hopefully it moves things forward... I'm sorry if the syntax of code and commenting should in some instances not adhere the drupal guidelines.
Big problem:
There seems to be something fishy about "add variation"->"cancel add variation" and then adding/editing again. As far as I could tell this problem is already in the module for "add variation" before this patch.
I would sure appreciate some help with this, so that you can choose any action (edit, clone, add variation), then cancel the form and use the actions again. Until that works it isn't really ripe for usage by "laymen", which is what we are trying to accomplish with this module.
Nota bene:
This patch also includes the reordering of the "abort" statements to allow changing weight between entities mentioned in this issue: http://drupal.org/node/1557966
Comment #2
leanderl CreditAttribution: leanderl commentedHopefully this time the patch is there... (previous attachment empty). (By the way it is still work in progress hence the stupid comments in some places...)
Comment #3
leanderl CreditAttribution: leanderl commentedHere's a cleaned up version of the patch. Seems to be working well. Needs review.
Comment #4
leanderl CreditAttribution: leanderl commentedNew patch which also includes andyg5000's "select_existing_product_entities" from issue http://drupal.org/node/1526084
Comment #5
leanderl CreditAttribution: leanderl commentedFound a bug with the "reordering" of weights part that prevented the entire form to be saved. This patch should hopefully do the trick. Needs community review...
Comment #6
bojanz CreditAttribution: bojanz commentedThe latest commits broke all patches in the queue (the code has changed drastically, sorry!), so this will need to be rerolled.
Provide only a patch for the clone button, the "reference existing" functionality already has its own issue and its own patch, no reason to merge it.
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous commented+1 for this functionality - this is exactly what I need. Any chance you could re-roll the patch @leanderl? Would be super appreciated!
Comment #8
leanderl CreditAttribution: leanderl commentedHi Jackocnr, I was actually working on a reroll yesterday, but there have been drastic changes to the code, just like bojanz mentioned, so it is kind of hard to get all the way. But hopefully there'll be a patch for "clone-button" soon. I'm really hoping bojanz and the others can help polish it up to be included in the regular module, because I really love what IEF does and it is a major leap in usability.
Comment #9
leanderl CreditAttribution: leanderl commentedHello, so here is a rerolled Clone button. It is quite rough around the edges and probably needs improvement, but it is a starting point. @bojanz I'm att DrupalCon Munich all week including all of friday. Would be great if we could get together and polish this up. Perhaps one would need a setting to enable/disable clone button, so as not to clutter the interface when a clone button is not desirable...
Comment #10
petu CreditAttribution: petu commentedHello @leanderl!
Thank you for the necessary functionality patch!
I've tried to apply it to inline_entity_form-7.x-1.x-dev version (from 2012-Oct-12). Here is log:
But have no luck :(.
Duplicate button appears but form is absent:
Any ideas how to make it works?
Comment #11
leanderl CreditAttribution: leanderl commentedHere's a clone button patch as of todays dev version of Inline Entity Form.
The clone button is enabled through "manage fields->product reference field" of the product display node.
There might be some more work needed on this, it has not been thouroghly tested, and I would be grateful for any help or feedback.
Comment #12
bojanz CreditAttribution: bojanz commentedThis is high on my IEF todo list. Haven't forgotten about it. Thank you for your efforts so far.
Comment #13
vasikethere were some issues with the previous patch
here is a reworked patch that make some changes:
- use the same form function(s) as add/edit
- it's supposed to work for every entity type, no only commerce product
the entity cloning preparation takes place in the "entity type" form controllers.
Comment #14
leanderl CreditAttribution: leanderl commented@vasike - what a hero you are! I look forward to trying your patch... Thanks for the effort!
Comment #15
gynekolog CreditAttribution: gynekolog commentedThanks for your work.
I have one problem. I have a taxonomy field "maker" in product. Widget type is autocomplete. When I'm creating variation by IEF and write new term to "maker" and use clone button, cloned variation have maker field empty.
If i write manually the same maker like in first variation and save product display, I have 2 same term in taxonomy.
All is OK if I save product display after creation first variation. But it resides. Is here some better solution?
Excuse my english, I'm trying to.
edit: My bad. Solution -> http://drupal.org/node/1723864#comment-6337706
Comment #16
pyrello CreditAttribution: pyrello commentedPatch in #13 worked for me. I have a fairly complex product entity and it worked very nicely. This saved my day! Thanks to everyone who has been working on this thread.
Comment #17
cocoshogo CreditAttribution: cocoshogo commentedNeeded this functionality as well. Applied patch #13 and I am getting this error :
Notice: Undefined index: clone_button EntityInlineEntityFormController->getSetting() (sites/my.site.com/modules/inline_entity_form/includes/entity.inline_entity_form.inc ファイル 124行).
(*Japanese is default language im using)
Any one know why im getting this. Im using the supported version of IEF; 7.x-1.1
Comment #18
vasike@cocoshogo : indeed. thank you Sir.
This is because the Clone settings for the IEF field wasn't defined and there's no default one.
here is the new patch that adds the Default Clone button settings for IEF widgets.
Comment #19
kevinsiji CreditAttribution: kevinsiji commentedPatch in #18 worked for me. It smoothly clones my products which are also added with "Commerce price table", and many list attributes.
Comment #20
Dave ReidThis works really great, but I actually think that the Clone button should be disabled by default, and not enabled by default. I found this very frustrating when applying the patch, and having to turn off the Clone button on several already production-ready fields.
Comment #21
cocoshogo CreditAttribution: cocoshogo commentedYes Patch in #18 worked :) thanx so much !
Comment #22
bojanz CreditAttribution: bojanz commentedI agree with #20.
I'd also like to explore making the cloning more generic, we know how to do the initial step, just like Entity API does:
The controllers could then reset any additional fields they'd want to (altering the sku, and so on).
I can do this prior to the commit, which will be sometime next week.
Comment #23
Dave ReidHere's a re-rolled version of #18 that is off by default for make files. Still doesn't account for the request in #22 so leaving as needs work.
Comment #24
vasikehere is a new patch that uses the entity_ui_clone_entity() function.
Comment #25
wangxb07 CreditAttribution: wangxb07 commentedhttps://drupal.org/sandbox/wangxb07/2036977
look this. Reference vasike patches, packaged into modules
Comment #26
sibiru CreditAttribution: sibiru commented#24
Thanks for creating this patch, it works on my project..
Are this patch applied on version & 7.1.2 ?
#25
Wow this is so good, are this module support generic entity? as @bojanz said in #22
Comment #27
tmsimont CreditAttribution: tmsimont commentedthis causes AJAX errors to occur if there is an element on the clone form that has an AJAX callback.
In the patch in #18, the error occurs on this line in inline_entity_form.module:
If using the patch in #25, this line in entity.ui.inc:
The error is:
Comment #28
tmsimont CreditAttribution: tmsimont commentedimage fields trigger this error
Comment #29
tmsimont CreditAttribution: tmsimont commentedthis error comes from this part of the patches
The assumption is that 'triggering element' will always be a trigger for a new cloned entity. In the case of image field uploads, or any other AJAX trigger, this assumption is not valid. If a field inside the clone form becomes a trigger during the form build operation, then Notice: #ief_row_delta is an undefined index in inline_entity_form_field_widget_form()
Comment #30
tmsimont CreditAttribution: tmsimont commentedpatch in 24 re-rolled to latest dev, and fix for issue brought up in 27-29 attached.
Comment #31
vasikehere is a new patch that extends "Reference cloning" with Node clone module integration for "Inline entity form - Single value".
I implemented here and not in other issue, as it's built on the same code.
ex. 1 product to 1 product display
- similar products with different brand and price.
node clone could save a lot of time adding new product/products display if there a lot of other identical data in their structure.
also removed a trailing whitespace
@tmsimont : of course, thank you Sir.
Comment #32
vasikeRetitling
Comment #33
kevinsiji CreditAttribution: kevinsiji commentedApplied patch in #30.
Working fine along with "commerce_pricing_attributes" also.
Comment #34
tmsimont CreditAttribution: tmsimont commentedi found another problem..
if you have an image field,
1) create a new "parent" entity (like a product display)
2) Create a new "child referenced entity that is clonable" (like a product variation)
3) Enter fields and upload an image to first child (product variation)
4) Clone first child (product variation)
5) remove image from cloned child (new product variation)
6) save cloned child
7) save parent (product display)
4 errors then crash your site:
Notice: Trying to get property of non-object in file_field_presave() (line 220 of ../file.field.inc)
Notice Undefined property: stdClass$uri in file_save() (line 556 of ... file.inc)
and then 2 of these:
PDO Exception .... Duplicate entry for key 'uri' into {file_managed}
It seems like the crash is related to this: #1443158: file_field_presave assumes that a file object has been loaded
But even when you apply patch in #17 in that issue, there's still a problem. The crash is averted but then the first child (product variation) loses its image.
Comment #35
tmsimont CreditAttribution: tmsimont commentedComment #36
vasikefor #34 issue with cloning new (unsaved) entities:
here is a new patch that saves the original entity if is new before cloning.
about core issue and its patch #1443158-17: file_field_presave assumes that a file object has been loaded it does get rid of the errors. but the image field of the original entity it will be empty as for the clone.
another approach (to avoid this issue) is to have the clone button only for already saved entities.
Comment #37
airb CreditAttribution: airb commentedhi! here is another project dealing good with previously uploaded files (so filefield can handle already existing files) https://drupal.org/project/imce_filefield - maybe helps.
how is it working now with filefields? i have a lot of fields on a production site, would be hard to test now... ill find another way if it's not ready for testing... thanks!
Comment #38
eneko1907 CreditAttribution: eneko1907 commentedAfter version 1.3, the patches at #18 and #36 cannot be applied. For 1.3, those still work, I ran basic tests (clone an existing entity), that's OK.
However, for versions 1.4 onwards the patches do not work. I adapted them for 1.5, with limited success: my patches apply fine, and the clone button appears. After I click the clone button, this produces the result I expect: a new pre-populated entity form appears with the cloned content used to pre-populate fields. Problem is the "Save" button does not save the cloned entity. Boo. The thing I cannot adapt is the changes for the 1.3 hook "inline_entity_form_process_entity_form", which disappeared in versions 1.4 onwards. In any way, it would be great to see the ability to clone and existing entity back again, sorry I couldnt get it to work for recent versions. For what is worth, here is my attempt to re-take this work. http://drupal.org/files/issues/ief_clone_button-1590146-38.patch (just to insist, it is not working)
Comment #39
Poieo CreditAttribution: Poieo commentedThis is really close. It actually works if you don't save the cloned variation and just save the entire product display.
Would love to get this working. I'll post back if I figure anything out.
Comment #40
dgastudio CreditAttribution: dgastudio commentedany update?
Comment #41
zengenuity CreditAttribution: zengenuity commentedI've made a few changes to the patch in #38 to make cloning save properly. This is working for me with commerce products on a commerce kickstart site. Have not tested in other situations, but the primary use case of most people on this thread (not having to re-upload the images for additional product variations) is working for me now on IEF 1.5 and head.
Comment #42
eneko1907 CreditAttribution: eneko1907 commentedAwesome, I will test it as soon as I can. BTW, we do not use this ief-clone-feature on the commerce kickstart.
Comment #43
eneko1907 CreditAttribution: eneko1907 commented#41 seems to be working on some tests I ran outside the scope of the commerce -- thank you so much
Comment #44
yenidem CreditAttribution: yenidem commented#41 worked for me, I use drupal commerce, it is not commerce kickstarter. Thank you very much for this feature.
Comment #45
annrockio CreditAttribution: annrockio commented#41 works for me too, in commerce kickstart. Thanks!
Comment #46
radimklaskaI tested #41 and it worked great. Our content person is happy again :-) Thanks!
Comment #47
Poieo CreditAttribution: Poieo commentedMarking this RTBC so we can hopefully get it committed. Thanks @zengenuity!
Comment #48
danreb CreditAttribution: danreb commented#41 works for me too in dev version of Inline Entity form.. worked great..
Thanks
Comment #49
Chithra K CreditAttribution: Chithra K commentedI tested this in Commerce Kicstart2 which uses the 7.x-1.5 version of Inline entity form and #41 just works fine! Thank you.
Comment #50
yannickooHere should be a space after
//
.This
elseif
should start in a new line.Comment #51
danreb CreditAttribution: danreb commentedcode from #41 + the cleanup suggestion from yannickoo. This is a very nice feature so hoping to be included in IEF
Thanks
Comment #52
danreb CreditAttribution: danreb commentedComment #53
danreb CreditAttribution: danreb commentedOk just to make sure.. don't know why the attachement doubled up... here it is again
Comment #54
yannickooAmazing! Thank you so much for this functionality Adolfo, the patch works fine for nodes. We need to check product and custom entities support.
Comment #55
slybud CreditAttribution: slybud commentedWell done guys and thank you for the work. The patch provided in #53 works fine for my use case
It works with special fields like files and images + it empties the SKU field of the duplicated entity => really nice in my case
I've also tested deletion of cloned product to make sure.
So thank you, I think we need one ore two more feedbacks to mark this as RTBC
Comment #56
nicktr CreditAttribution: nicktr commented#53 works great!! Thank you Danreb and all other contributors!
Comment #57
haggins CreditAttribution: haggins commented#53 works. Images are also cloned. Thank you!
Setting to RTBC due to #54 - #57
Comment #58
djdevinWe've been using this in production for about 3 months now, works as expected.
- Node with an IEF field, referencing a single instance of an Entity type with a bunch more fields
- Cloning the node, also clones the referenced Entity
Comment #59
bojanz CreditAttribution: bojanz commentedGood job everyone, this is almost done.
Let's create a clone() method on the controller, use it for this purpose, call it from inline_entity_form_clone_entity(). It will make the code cleaner.
No, we can't do this. Only saving the parent form can trigger other saves.
There's no reason why the cloned unsaved entity shouldn't work just like the original unsaved entity does, feels like an error on our side?
Let's retest without the workaround, since it's 2 years old, and both Core and Entity API have changed since.
Let's make this title more user friendly. t('Allow users to clone @label.', array('@label' => $labels['plural']))
Let's remove the node_clone integration. This code won't work with nested IEF widgets, and the "remove references on clone" logic doesn't belong in a field widget.
I'm working on fixing this.
Comment #60
bojanz CreditAttribution: bojanz commentedHere's a new patch. It addresses my feedback, performs additional cleanup, checks whether cardinality has been reached and entity access is allowed before showing the Clone button.
Please give it a test, paying special attention to the previously mentioned ajax problems.
Comment #61
njbarrett CreditAttribution: njbarrett commentedI manually tested the patch and had a few usability issues. I noticed that on a field with cardinality of 1 using the multiple value widget, the clone button is hidden because the field can only have 1 value. Is there anyway I can clone an existing entity in this case? There's no indication that the feature doesn't work on fields with a cardinality of 1, as it's still enabled on the single value widget as an option that does nothing.
I would love to be able to have a button next to "add existing entity" that says "clone existing entity" which has an autocomplete text field just like the "add existing entity" button but instead of just adding it, it clones it first and then adds it. Seems like then it could work even on fields with a cardinality of 1, and also when #2134035: Allow to add existing entities using the single value field widget gets committed it could work on on the single value widget as well.
Comment #62
bojanz CreditAttribution: bojanz commentedNo, because you've reached the maximum number of values the underlying reference field can accept.
There's no workaround for that.
That's unrelated to the current feature request.
Comment #63
njbarrett CreditAttribution: njbarrett commentedOk I misunderstood the requirements of the issue. I guess it helps people who want to clone other referenced entities but not clone entities that aren't already referenced.
In that case I still believe there shouldn't be the option to allow users to clone entities on the inline form single value widget, as it's not possible.
Comment #64
eneko1907 CreditAttribution: eneko1907 commentedTested patch at #60, clone functionality is there, working well for my use case.
Thanks!
Inigo
Comment #65
ASGAlex CreditAttribution: ASGAlex commented#60 works well, but with "Auto generate the product title" setting there is small misleading bug: after cloning an variation the title field is shown like cloned too. Autogeneration itself will be triggered on product save.
When adding product variation with title autogeneration, the message "Will be auto-generated when the form is saved." displays in place of title.
Comment #66
bojanz CreditAttribution: bojanz commentedCommitted #60.
Thank you everyone for this amazing multi-year effort.
Comment #69
John Pitcairn CreditAttribution: John Pitcairn commented@ASGAlex: I opened a new issue for #65: https://www.drupal.org/node/2561355
Comment #70
RAWDESK CreditAttribution: RAWDESK commentedGreat effort to improve usability ! I am in big favour of #60
Comment #71
BITANUBE CreditAttribution: BITANUBE commented+1000 for the patch #60 . Can't not be applied with drush or patch manager but manually was a great solution.
Congratulations !
Comment #72
bojanz CreditAttribution: bojanz commented@BITANUBE
There's nothing to apply, it has been in -dev for the last 8 months.
Comment #73
BITANUBE CreditAttribution: BITANUBE commentedOuch ! Thanxs ! For the next time !
Comment #74
belaustegui CreditAttribution: belaustegui commented@bojanz I'm trying to find this functionality in the 8.x version of this module, but it seems that it is only available in the 7.x version.
Is this correct?
Comment #75
bojanz CreditAttribution: bojanz commented@belaustegui
Correct, nobody has ported it yet.
Comment #76
AntiNSA CreditAttribution: AntiNSA commentedWhere is it in the version? I am trying to clone variant... but cant find it anywhere...
Comment #77
ilya.no CreditAttribution: ilya.no as a volunteer and at Skilld for Skilld commentedHello all!
Thanks for your efforts and the patch! I've created D8 patch, based on it. As stated in this comment, I've used "Duplicate" instead of "Clone". Patches are for 8.x-1.0-beta1 and dev versions.
Comment #78
ilya.no CreditAttribution: ilya.no as a volunteer and at Skilld for Skilld commentedComment #79
Lukas von BlarerThis issue is closed. Can a maintainer re-open it or otherwise we create a new one.
Comment #80
bojanz CreditAttribution: bojanz commentedOpened #2962706: Add the ability to duplicate referenced entities and moved the #77 patch here.
In the future please don't respond to closed issues, I completely missed this.