0

I created a custom entity type using entity_info_hook and associative hooks. It works fine. Now I want to create a clone of the entity when I press the button Duplicate. Is there any method for this? I read Replicate module do this finely. But I can't find any sufficient tutorial for the purpose. How can I use entity_ui_clone_entity() in my module?

2

You could call Replicate's replicate_entity_by_id($entity_type, $id) method. And maybe hook it's API for custom behavior, see here.

entity_ui_clone_entity won't create the new entity, but only prepare your entity for creation, and could be used like this:

$my_clone = entity_ui_clone_entity('your_bundle', $my_entity);
entity_save('your_bundle', $my_clone);

Or if you created a method for saving your entity, use it direclty:

my_entity_save($my_clone);
| improve this answer | |
  • Just a note that you should be passing in entity type (e.g. 'node') as the first argument in entity_ui_clone_entity(), not bundle. – othermachines Jul 14 '16 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.