'Webform Associations', 'description' => t('Webform Associate allows you to auto create a webform when an associated content type is created. Associated webforms are auto appended to the bottom of the associated node.'), 'page callback' => 'drupal_get_form', 'page arguments' => array('webform_associate_admin'), 'access arguments' => array('administer webform associations'), 'type' => MENU_NORMAL_ITEM, ); return $items; } function webform_associate_menu_alter(&$items) { $webform_items = webform_menu(); foreach ($webform_items as $key => $item) { if (strpos($key, 'node/%webform_menu') !== FALSE) { $new_key = str_replace('node/%webform_menu', 'node/%webform_associate_webform', $key); // Use the existing router item which has, e.g., the 'module' set $items[$new_key] = $items[$key]; $callback = $items[$new_key]['access callback']; $items[$new_key]['access callback'] = 'webform_associate_menu_access'; $arguments = $items[$new_key]['access arguments']; switch ($callback) { case 'node_access': $items[$new_key]['access arguments'] = array($callback, $arguments, 1); break; case 'user_access': $items[$new_key]['access arguments'] = array($callback, $arguments, 1); break; case 'webform_submission_access': if ($new_key == 'node/%webform_associate_webform/submissions' || $new_key == 'node/%webform_associate_webform/submissions') { $items[$new_key]['access arguments'] = array($callback, $arguments, 1); } else { $items[$new_key]['access arguments'] = array($callback, $arguments, 1, 3); } break; case 'webform_results_access': $items[$new_key]['access arguments'] = array($callback, $arguments, 1); break; } unset($items[$key]); } } } function webform_associate_menu_access($func, $arguments = array(), $node, $a3 = NULL) { $vars = variable_get('webform_associate_nodes', array()); if (!in_array('webform', $vars)) { $vars[] = 'webform'; } foreach ($vars as $var) { if ($node->type == $var) { switch ($func) { case 'node_access': return $func($arguments[0], $node->nid); break; case 'user_access': return $func($arguments[0]); break; case 'webform_submission_access': if (!$a3) { return $func($node->nid, '', $arguments[2]); } else { return $func($node->nid, $a3, $arguments[2]); } break; case 'webform_results_access': return $func($node, $arguments[1]); break; } } else { return FALSE; } } } /** * Menu loader function. Given a nid, load the associated webform. */ function webform_associate_webform_load($nid) { $node = node_load($nid); if ($node->type != 'webform') { $ids = webform_associate_lookup($nid); if (isset($ids->wid)) { $node = node_load($ids->wid); } } return $node; } function webform_associate_menu_load($nid) { $wid = webform_associate_lookup($nid); $node = node_load($wid); return $node; } function webform_associate_perm() { return array('administer webform associations'); } function webform_associate_content_types() { $types = content_types(); foreach ($types as $type) { if ($type['type'] != 'webform') { $node_types[$type['type']] = $type['name']; } } return $node_types; } function webform_associate_admin() { $form = array(); $form['types'] = array( '#type' => 'checkboxes', '#title' => t('Content Types'), '#description' => t('Please select the types of content with which you would like to associate a webform creation utility.'), '#options' => webform_associate_content_types(), '#default_value' => variable_get('webform_associate_nodes', array()), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save Settings'), ); $form['reset'] = array( '#type' => 'submit', '#value' => t('Reset Settings'), '#submit' => array('webform_associate_admin_reset'), ); return $form; } function webform_associate_admin_submit($form, &$state) { variable_set('webform_associate_nodes', $state['values']['types']); } function webform_associate_admin_reset() { variable_set('webform_associate_nodes', array()); } function webform_associate_redirect($form, &$form_state) { $ids = webform_associate_lookup(arg(1), 'wid'); if ($ids) { $url = 'node/'. $ids->nid .'/edit/components'; } $form_state['redirect'] = $url; } function webform_associate_form_alter(&$form, $form_state, $form_id) { switch ($form_id) { case 'webform_client_form_'. arg(1): if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'submission' && is_numeric(arg(3))) { $ids = webform_associate_lookup($form['submission']['#value']->nid, 'wid'); if ($ids) { $node = node_load($ids->nid); $form['submission_info']['form']['#value'] = '