Trying to find some Best Practices that should be adopted to make modules webform 3.x module compliant.
Initial post taken from Salesforce Webform http://drupal.org/node/1146084

Comments

chriscalip’s picture

With the introduction of the feature "Web Enabled Content Types" see admin/settings/webform in the Webform 3.x module one practice that we module developers have been doing is rendered obsolete.

a.) the practice of form id based checks are not effective anymore.

// INSTEAD OF :
if ( ereg('^webform_client_form_', $form_id) ) : 
if ( $form_id == 'webform_node_form' )  :

// USE THIS INSTEAD:
if (!empty($form['#node']->webform))
// on hook_nodeapi section

// INSTEAD OF the obsolete check of 
if ( $node->type == 'webform') :

// USE THIS INSTEAD:
  $webform_node_types = webform_variable_get('webform_node_types');
  if ( in_array($node->type, $webform_node_types)) :

b. ) The old way of handling editing of "CRUD" webform nodes are also obsolete.

// INSTEAD OF :
if ( $form_id == 'webform_node_form' ) :

// USE THIS INSTEAD:
if (!empty($form['webform']['#type'])):
chriscalip’s picture

Make use of Webform 3.x hooks available see /webform/webform_hooks.php

a. With the availability of webform hooks our form alter's to add submission handlers are no longer necessary

// INSTEAD OF
if ( ereg('^webform_client_form_', $form_id) ) {
    // Add the submit handler after the existing Webform submit handler,
    // but before the second Webform handler. Pop off the first one and add
    // ours second.
    $first = array_shift($form['#submit']);
    array_unshift($form['#submit'], $first, 'salesforcewebform_client_submit');
}
// Use THIS INSTEAD :
// after the webform got saved to the database
hook_webform_submission_insert($node,$submission);
// Modify a Webform submission, prior to saving it in the database.
hook_webform_submission_presave($node, &$submission)

What's the advantage? We got the $sid already available... well the hook_webform_submission_insert does.

chriscalip’s picture

Status: Needs review » Active
quicksketch’s picture

Issue summary: View changes
Status: Active » Closed (fixed)

Closing, as this seems to be mostly informational for users upgrading to Webform 3.x(?) With 4.x out shortly, hopefully by now all modules have migrated fully to 3.x.