I expect that in most cases, a given PDF used with Webform always draws its data from the same Webform node. So, I suggest that on the "Edit PDF form" page, there should be a preference where one can set the default node from which to draw form data. For example, if one visited a URL like fillpdf?fid=1, it would use that default node.

This would allow a custom module to hook into this to more easily provide links to the filled version of the form. It could add to each Webform links to the filled versions of PDFs that refer to that Webform. There could be other ways of automating link generation which would benefit from this.

Comments

liam morland’s picture

Status: Active » Needs review
StatusFileSize
new5.09 KB

Patch implementing this attached. It does two things:

  1. Add a DB field and UI to set the default_nid for each PDF.
  2. Use the default_nid when filling a PDF if no nid is provided.

This patch incorporates the fix for #1356304: Webform query broken when no sid given because it changes that area of code and depends on that fix having been made.

wizonesolutions’s picture

Can you re-roll this without #1356304: Webform query broken when no sid given since it is now committed?

Other than that, I approve of the way you did this and am willing to add this function, especially since many PDF forms *are* linked to a specific Webform (nid). I'll commit it once you re-roll.

liam morland’s picture

StatusFileSize
new4.99 KB

Thanks. Attached is a re-rolled patch.

wizonesolutions’s picture

Status: Needs review » Needs work

Some comments on this for whichever one of us gets to them first.

+++ b/fillpdf.admin.incundefined
@@ -194,6 +194,14 @@ function fillpdf_form_edit($form, &$form_state, $fid) {
+    '#title' => t('Default data source node ID'),

Call this "Default Node ID".

+++ b/fillpdf.admin.incundefined
@@ -194,6 +194,14 @@ function fillpdf_form_edit($form, &$form_state, $fid) {
+    '#description' => t('When filling a PDF, use this node for the data source if no node is specified in the fill URL.'),

"in the Fill PDF URL"

+++ b/fillpdf.admin.incundefined
@@ -194,6 +194,14 @@ function fillpdf_form_edit($form, &$form_state, $fid) {
+    '#maxlength' => 10,

Maybe this is overdoing it, unless Postgres and MySQL both have int(10) as a default. If that's the case, I'm fine with it.

+++ b/fillpdf.moduleundefined
@@ -256,14 +279,16 @@ function fillpdf_merge_pdf($fid, $nids = NULL, $webform_arr = NULL, $sample = NU
+        if (empty($webform['sid'])) { // user didn't specify submission-id, meaning they want most recent

Can you fix the comment here to the revised one? You can see it in the first subtracted line in this block.

+++ b/fillpdf.moduleundefined
@@ -256,14 +279,16 @@ function fillpdf_merge_pdf($fid, $nids = NULL, $webform_arr = NULL, $sample = NU
+            WHERE nid = :nid AND uid = :uid ORDER BY submitted desc', array(':nid' => $webform['nid'], ':uid' => $user->uid))->fetchField();

Can you also make this query consistent (DESC vs. desc)? Used to be like that anyway.

liam morland’s picture

Status: Needs work » Needs review
StatusFileSize
new4.98 KB

I think I got the maxlength 10 from somewhere else that referenced node IDs.

Updated patch with other changes attached.

wizonesolutions’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Needs review » Patch (to be ported)

Tested this with a node and webform, and it looks like it works fine. Committed. When you re-roll #1404354: Fill PDF settings: Hide Configure fillpdf-service.com when not in use, I will cut a new official release.

Needs backport.

liam morland’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new5.9 KB

D6 version attached. Apply after #1430390: Coding standards: remove whitespace.

wizonesolutions’s picture

Status: Needs review » Needs work

Looks good overall. Almost there, but:

+++ b/fillpdf.moduleundefined
@@ -219,14 +242,17 @@ function fillpdf_merge_pdf($fid, $nids = null, $webform_arr = null, $sample = nu
+    foreach ($webform_arr as $webform) {
+      if (!empty($webform['nid'])) {
+        if (empty($webform['sid'])) { // User did not specify submission ID, meaning they want most recent.
+          $webform['sid'] = db_query('SELECT sid FROM {webform_submissions}
+            WHERE nid = :nid AND uid = :uid ORDER BY submitted DESC', array(':nid' => $webform['nid'], ':uid' => $user->uid))->fetchField();
+        }
+        $webforms[] = array(
+          'webform' => empty($webform['node']) ? node_load($webform['nid']) : $webform['node'],
+          'submission' => webform_get_submission($webform['nid'], $webform['sid']),

I think this snuck in here. Can you re-roll without this?

liam morland’s picture

It's in the D7 version of the patch.

  • Commit e9a3654 on 7.x-1.x, 7.x-2.x, 7.x-2.x-tests1, 7.x-1.x-ubercartbackporttest authored by Liam Morland, committed by wizonesolutions:
    Issue #1393012: Allow specifying default node.
    
    This works with Webform...

liam morland’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Issue summary: View changes
Status: Needs work » Closed (fixed)

Drupal 6 is no longer supported.