Hi All,

I took a look at the webform views and realized there is no an option to add a "CLONE" operation for submissions, the existing ones are VIEW, EDIT, DELETE.

Please take a look at the image to see what I am taking about.

Is this possible to do? I mean I heard about Node Clone module but I just dont want to install a separate module to do just one operation.

Thanks

Comments

yaach’s picture

Actually I just enable Node Clone module and although it allows me to clone a Webform Node, it DOES NOT allow me to clone a submission.

Anoybody?

danchadwick’s picture

Category: Feature request » Support request
Status: Active » Fixed

This will require custom programming. You can add a command to do the clone. You can then add the link from the view that generates the list of submissions (webform_submissions or webform_submission_NID).

Status: Fixed » Closed (fixed)

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

yaach’s picture

Assigned: Unassigned » yaach
Status: Closed (fixed) » Needs review
StatusFileSize
new11.26 KB

Hi All,

Thanks to @DanChadwick suggestion, I have implemented the feature to clone submitted data. This works pretty much like the edit or delete commands:

In order to enable the Clone feature, do the following steps:

  1. Add the Clone field link for the View that is displaying the results.
  2. On the views result page, look for the "Clone" link under then Operations column
  3. Select the submission you want to clone and click on the "Clone" link.
  4. Confirm you want to clone the submission data.
  5. Done!. You will have now a cloned submitted data.

The goal that makes me create this feature was because I am doing a very long form that users fill out in a yearly basis, then next year they need to fill out the same form and most of the time all the fields are the same.

Hope that helps anybody needing this.

Status: Needs review » Needs work

The last submitted patch, 4: ability_to_clone_submission_data-2496563-4.patch, failed testing.

danchadwick’s picture

This is nicely done. I am willing to commit parts of this so that someone can add a clone link to the view if they want. I don't want to add a clone tab, but someone would enable that using hook_menu_alter to change the MENU_CALLBACK to a LOCAL_TASK.

I read the patch over and have these comments:

  1. +++ b/includes/webform.submissions.inc
    @@ -210,6 +210,39 @@ function webform_submission_delete($node, $submission) {
    +  // Iterate through all components and let each do cleanup if necessary.
    +  foreach ($node->webform['components'] as $cid => $component) {
    +    if (isset($submission->data[$cid])) {
    +      webform_component_invoke($component['type'], 'delete', $component, $submission->data[$cid]);
    +    }
    +  }
    

    I don't think the delete method should be invoked. The submission is still valid in the original submission.

  2. +++ b/includes/webform.submissions.inc
    @@ -210,6 +210,39 @@ function webform_submission_delete($node, $submission) {
    +  $submission->completed = REQUEST_TIME;
    

    Request time should not be set if it is 0 (i.e. a draft). If you clone a draft, it should not get a complete timestamp.

  3. +++ b/webform.module
    @@ -384,6 +384,17 @@ function webform_menu() {
    +    'type' => MENU_LOCAL_TASK,
    

    We could make the a menu callback. Users could then change it to a local task with hook_menu_alter to make the clone tab appear.

  4. +++ b/webform.module
    @@ -633,6 +644,8 @@ function webform_submission_access($node, $submission, $op = 'view', $account =
    +    case 'clone':
    +      return $module_access || ($general_access && (user_access('clone all webform submissions', $account) || (user_access('clone own webform submissions', $account) && $account->uid == $submission->uid)));
    

    I think the permission for clone should be the same as VIEW and SUBMIT. If you can view the submission and can submit the form, then you could copy the submission down with pencil and paper and submit a new one.

  5. +++ b/webform.module
    @@ -726,6 +739,10 @@ function webform_permission() {
    +    'clone all webform submissions' => array(
    +      'title' => t('Clone all webform submissions'),
    +      'description' => t('Allows cloning of any webform submission by any user. Generally an administrative permission.'),
    +    ),
    
    @@ -735,6 +752,9 @@ function webform_permission() {
    +    'clone own webform submissions' => array(
    +      'title' => t('Clone own webform submissions'),
    +    ),
    

    Also not needed.

danchadwick’s picture

Category: Support request » Feature request
yaach’s picture

Hi Dan,

Not sure if I understand well your comment #5 on the patch. Every user will
have the ability to clone their submitted data and I am using the "View your
previous submissions" option so that users can see their list and clone from
there. Last time I checked, I couldn't get the clone link on the view unless
I set permissions.

Thanks

danchadwick’s picture

Not sure if I understand well your comment #5 on the patch.

What I mean is that I would propose to NOT introduce new permissions for Clone. Instead, the permission to clone would be the relevant permission to view the particular submission PLUS (logical AND) permission to create a new submission, because that's what clone is functionally.

You would still need to customize your particular view to include the clone link, and, if you want it, convert the Clone menu callback into a local task to make the tab appear. I would love to find a way to infer whether the user wants to allow cloning, but I don't know what that would be. We can't go looking for the clone handlers in the view, for example.

yaach’s picture

Status: Needs work » Needs review
StatusFileSize
new9.64 KB

Ok, so I made some changes for the feature based on @DanChadwick suggestions and comments.

Status: Needs review » Needs work

The last submitted patch, 10: webform-ability_to_clone_submission_data-2496563-10.patch, failed testing.

yaach’s picture

Hi Dan,

Does this new feature will be merged anytime soon?

Thanks

danchadwick’s picture

We need to get tests working first. If you can help with that, it will speed things. I'm also on vacation for a few weeks so won't be working on code for a while.

I still support the feature tho.

yaach’s picture

Sure I will make some tests..enjoy.

danchadwick’s picture

Sorry to not be clear. I'm not looking for clone tests, although they are welcome. Existing tests don't pass. That needs attention.

EDIT: This: #2510216: Tests are failing (Testbot, local via UI, drush test-run

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 10: webform-ability_to_clone_submission_data-2496563-10.patch, failed testing.

danchadwick’s picture

Version: 7.x-4.9 » 7.x-4.x-dev
Status: Needs work » Needs review

danchadwick’s picture

Status: Needs review » Needs work

I installed and tested your patch.

In general, there are two approaches for cloning content:
1) Clone the content, then allow the user to edit the clone.
2) Create a new piece of content with the form already filled in with the cloned content.

Webform already clones components and uses approach 2. I was surprised when cloning a submission, it used technique 1. If technique 2 were used, there would be no need for a confirming page prior to the clone. webform_client_form() accepts a $submission argument, which could be created from the cloned submission and adjusted to create a new submission. At a minimum, you would need to remove or set the sid, serial, and dates as needed. Maybe other stuff too.

Also, I don't see that all the needed permissions are correct. What exactly they are would depend upon which cloning approach is used.
1) To clone-and-save, you need permission to view the submission plus permission to add another submission, including checks that are made on the node view page (where new submissions are made), plus permission to edit the submission (because to change the clone you need to edit it).
2) To add-with-clone-data, you need permission to view the submission plus permission to add another submission. You don't need the edit permission.

danchadwick’s picture

Status: Needs work » Closed (won't fix)

Closing for lack of activity. Please do re-open if there is continued work on this.

kyleheney’s picture

Hi,

I see that this is closed, but I just wanted to add my desire to see a feature like this added to Webform. Cloning Submissions would be very useful for me, as I use Webform to create invoices, etc... it would be great if a user could clone a previously created invoice so they have some information pre-filled and would only need to add/update certain fields.

It seems like permissions are holding this up a bit, but if it gets looked at again, I'd be happy to help test it and/or contribute where possible.

Thanks

yaach’s picture

Hi @kyleheney, you can try the patched I provided. It worked for me. Get it a try and let me know.

kyleheney’s picture

I'm hesitant to implement a patch that the maintainer of Webform won't consider. I use webforms throughout my site, so if this feature isn't properly supported, a future update could break my forms. I don't think I'm comfortable trying this unless @DanChadwick were to implement it in the Webform module.

kyleheney’s picture

@yalegria... does your patch only work when a user has the "edit submission" permission? In my case, my user does not have the edit submission permission (just view submission), so I'm not sure if your patch would work for me.

Ideally, I'd only want the user to be able to edit the cloned content (prior to submission), so a new submission would need to be created that auto-populated the new form with the previous data. If I understand your patch correctly, this is NOT how your patch works...? Correct me if I'm wrong.

Thanks

pixelshrink’s picture

Just wanted to add my support to this feature, it would be great if it makes it into a future release.

druliner’s picture

Patch #10 breaks with webform 7.x-4.15 so here's a new on that works with no other changes.

I'd love to see this feature added as well. If someone does work on it I'd prefer permissions option 2 that Dan mentions in comment 20. Also change user to the current user on clone. Thanks community.

akrem.ajroudi’s picture

thank you druliner for your patch but you must edit this line :
FILE : webform\views\default_views\webform_submissions.inc
$handler->display->display_options['fields']['clone_submission']['field'] = 'delete_submission';
TO :
$handler->display->display_options['fields']['clone_submission']['field'] = 'clone_submission';

drumanuel’s picture

Needed this patch for 4.18 so I ported it and it seems to work nicely

drumanuel’s picture

rex.barkdoll’s picture

Hi @Drumanuel,

Thank you very much for posting an updated version of your patch.
I just tried to implement it with Webform version 7.x-4.23. Something seems to break and I don't have the coding chops to understand what's gone wrong.

If I disable "Verify submission access for each link" I can get the clone button to show up, but it only sends me to a result detail page and doesn't prompt me for any further action.

I know we're all in the process of moving toward D8, but I've got a few clients who are asking me to see if we can get this working in the mean time.

Thanks for all your work and if you can spare any time on this now :)