Commit 4de63ceb authored by dandaman's avatar dandaman Committed by kvnm

Issue #2377531 by dandaman: Support A.net Webforms on content types other than Webform

parent 8049ce45
......@@ -17,6 +17,8 @@ define('AUTHORIZENETWEBFORM_MODE','live'); // Can be 'live' or 'test'.
* with a credit or debit card through Authorize.Net
*/
function authorizenetwebform_form_alter(&$form, &$form_state, $form_id) {
$webform_types = webform_node_types();
// handle webform client forms (instances of webforms that are submitted)
// webform names client forms with the pattern web_form_client_form_$nid, use this knowledge to
// manipulate the forms that webform displays
......@@ -26,7 +28,7 @@ function authorizenetwebform_form_alter(&$form, &$form_state, $form_id) {
$node = $form['#node'];
// only deal with this form if it is supposed to go to Authorize.Net
if (empty($node->use_authorizenet)) {
if (!isset($node->use_authorizenet) || empty($node->use_authorizenet)) {
return ;
} else {
// new validation handler
......@@ -40,7 +42,7 @@ function authorizenetwebform_form_alter(&$form, &$form_state, $form_id) {
break;
// handle editing of webform nodes
case ($form_id == 'webform_node_form'):
case (substr($form_id, -10) === '_node_form' && in_array(substr($form_id, 0, -10), $webform_types)):
/* Collapse the email info on the page assuming that it is going to be an Authorize.net form */
$form['mailsettings']['#collapsed'] = TRUE;
......@@ -73,7 +75,7 @@ function authorizenetwebform_form_alter(&$form, &$form_state, $form_id) {
case ($form_id == 'webform_component_edit_form'):
$node = node_load($form['nid']['#value']);
// if the user has specified the Authorize.Net action, then we will be posting the form to Authorize.Net
if ($node->use_authorizenet) {
if (isset($node->use_authorizenet) && $node->use_authorizenet) {
module_load_include('inc', 'authorizenetwebform', 'authorizenetwebform_fields');
foreach (authorizenetwebform_available_fields() as $anwafkey => $anwafvalue) {
$anwafkey = strtolower($anwafkey);
......@@ -123,7 +125,14 @@ function authorizenet_field_key_submit($form, &$form_state) {
*/
function authorizenetwebform_node_load($nodes, $types) {
// Reject if none of the nodes are webforms.
if (!in_array('webform', $types)) {
$webform_types = webform_node_types();
$contains_webform = FALSE;
foreach ($nodes as $node) {
if (in_array($node->type, $webform_types))
$contains_webform = TRUE;
}
if (!$contains_webform) {
return;
}
......@@ -138,7 +147,8 @@ function authorizenetwebform_node_load($nodes, $types) {
* Implementation of hook_node_insert().
*/
function authorizenetwebform_node_insert($node) {
if ($node->type == 'webform') {
$webform_types = webform_node_types();
if (in_array($node->type, $webform_types)) {
db_insert('authorizenetwebform')
->fields(array(
'nid' => $node->nid,
......@@ -152,7 +162,9 @@ function authorizenetwebform_node_insert($node) {
* Implementation of hook_node_update().
*/
function authorizenetwebform_node_update($node) {
if ($node->type == 'webform' && isset($node->use_authorizenet)) {
$webform_types = webform_node_types();
if (in_array($node->type, $webform_types) && isset($node->use_authorizenet)) {
db_merge('authorizenetwebform')
->key(array('nid' => $node->nid))
->insertFields(array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment