I have a situation where it would be useful to be able to return a webform to draft status. In looking at the codebase this seems like a straightforward change. I will try to work out how to get this done and submit here for community review. In the meantime, any advice for a new-to-Drupal coder would be appreciated.

Comments

chuck_theobald created an issue. See original summary.

chuck_theobald’s picture

I've managed to get a new unsubmit function installed and triggering from a webform rule. I'm still working out how to get the submission id, which is a kind of chicken-and-egg thing. My first issue, though, is actually saving to the database.

I've got the following function modeled after webform_rules_submissions_load:

/**
 * Rules action callback to change a webform submission from submitted to draft.
 * @author Chuck Theobald
 */
function webform_rules_submission_unsubmit($nid, $sid) {
  // Make sure the needed functions are available.
  module_load_include('inc', 'webform', 'includes/webform.submissions');

  // Load the node and submission.
  $node = node_load($nid);
  //$submission->setSticky(!$submission->isSticky())->save();

  //$sid = $submission->id();
  $submission = webform_get_submission($node->nid, 62);

  dpm($submission);

  // Change submission data.
  $submission->is_draft = "1";
  dpm($submission);

  // Finally, update the submission.
  webform_rules_webform_submission_update($node, $submission);
}

As you can see, I am working around the sid thing with a hard-coded sid. Also, dpm() confirms that the $submission object is being updated. Still, the above fails to update the submission in the database. The log shows warnings and notices about an undefined index 'webform' at lines 213 and 216 of webform_rules.module, along with the accompanying message about parameter 1 to array_keys().

I would not think that these would prevent updating the submission record, but it is still showing up as completed rather than draft. The rule does not reference any selector associated with webform, just referring to node:nid. Any advice or hints would be appreciated.

chuck_theobald’s picture

Status: Active » Closed (outdated)