### Eclipse Workspace Patch 1.0
#P Nodeformtemplate D6 Conversion
Index: nodeformtemplate.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodeformtemplate/nodeformtemplate.module,v
retrieving revision 1.11
diff -u -r1.11 nodeformtemplate.module
--- nodeformtemplate.module	17 Apr 2007 18:00:13 -0000	1.11
+++ nodeformtemplate.module	13 Mar 2009 04:02:30 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: nodeformtemplate.module,v 1.11 2007/04/17 18:00:13 egonbianchet Exp $
+// $Id$
 
 /**
  * @file
@@ -9,9 +9,9 @@
 /**
  * Implementation of hook_help()
  */
-function nodeformtemplate_help($section) {
-  switch ($section) {
-    case 'admin/content/types/' . arg(3) . '/nodeformtemplate':
+function nodeformtemplate_help($path, $arg) {
+  switch ($path) {
+    case 'admin/content/node-type/'. $arg[3] .'/nodeformtemplate':
       return t("Write the text that you want to be used as a template when creating new <em>%type</em> nodes. Words starting with a % sign will be replaced with the query string parameter having the same name.", array('%type' => node_get_types('name', arg(3))));
   }
 }
@@ -26,17 +26,18 @@
 /**
  * Implementation of hook_menu()
  */
-function nodeformtemplate_menu($may_cache) {
+function nodeformtemplate_menu() {
   $items = array();
-  if (!$may_cache && node_get_types('name', arg(3))) {
-    $items[] = array (
-      'path' => 'admin/content/types/' . arg(3) . '/nodeformtemplate',
-      'title' => t('Form template'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array(arg(3) . '_template_node_form'),
-      'access' => user_access('administer form templates'),
+  foreach (node_get_types() as $type) {
+    $type_url_str = str_replace('_', '-', $type->type);
+  
+    $items['admin/content/node-type/'. $type_url_str .'/nodeformtemplate'] = array(
+      'title' => 'Form template',
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array($type->type .'_template_node_form', NULL, $type),
+      'access arguments' => array('administer form templates'),
       'type' => MENU_LOCAL_TASK,
-      'weight' => 10,
+      'weight' => 1,
     );
   }
   return $items;
@@ -48,7 +49,7 @@
 function nodeformtemplate_forms() {
   $forms = array();
   foreach (node_get_types() as $type) {
-    $forms[$type->type . '_template_node_form'] = array(
+    $forms[$type->type .'_template_node_form'] = array(
       'callback' => 'nodeformtemplate_template_form',
       'callback arguments' => array($type)
     );
@@ -59,22 +60,27 @@
 /**
  * Prepare template forms
  */
-function nodeformtemplate_template_form($type) {
+function nodeformtemplate_template_form(&$form_state, $type) {
+  module_load_include('inc', 'node', 'node.pages');
   $node = new stdClass();
   $node->type = $type->type;
 
   // We use this flag to know wether we are in a real node form in hook_nodeapi
-  $node->formtemplate_settings = true;
+  $node->formtemplate_settings = TRUE;
 
-  $form = drupal_retrieve_form($node->type . '_node_form', $node);
+  $form_state = array();
+  $form = drupal_retrieve_form('node_form', $form_state, $node);
   foreach (module_implements('form_alter') as $module) {
     $function = $module .'_form_alter';
-    $function($node->type . '_node_form', $form);
+    $form_name = $node->type .'_node_form';
+    $function($form, $form_state, $form_name);
   }
 
-  $form['#id'] = $node->type . '_template_node_form';
-  $form['#base'] = 'nodeformtemplate_template_form';
-  $form['reset'] = array('#type' => 'submit', '#value' => t('Reset'), '#weight' => 50);
+  $form['#id'] = $node->type .'_template_node_form';
+  $form['#submit'] = array('nodeformtemplate_template_form_submit');
+  $form['#validate'] = array();
+  unset($form['buttons']['submit']['#submit']);
+  $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset'), '#weight' => 50);
 
   // unset some known unsupported fields
   foreach (array('author', 'options', 'taxonomy', 'menu') as $field) {
@@ -85,7 +91,7 @@
   foreach (element_children($form['body_filter']['format']) as $key) {
     $form['body_filter']['format'][$key]['#disabled'] = TRUE;
   }
-  unset($form['preview']);
+  unset($form['buttons']['preview']);
 
   // remove node validation code and disable non-text fields
   _nodeformtemplate_prepare_template_form($form);
@@ -101,6 +107,7 @@
     if (is_array($form[$key])) {
       if (element_child($key)) {
         // disable validation
+        unset($form[$key]['#element_validate']);
         unset($form[$key]['#validate']);
         $form[$key]['#required'] = FALSE;
         // disable all non-text fields
@@ -117,25 +124,27 @@
 /**
  * Saves a template
  */
-function nodeformtemplate_template_form_submit($form_id, $form_values) {
-  switch ($form_values['op']) {
+function nodeformtemplate_template_form_submit($form, &$form_state) {
+  switch ($form_state['values']['op']) {
 
-    case t('Submit'):
+    case t('Save'):
       foreach (array('nid', 'vid', 'uid', 'created', 'changed') as $field) {
-        unset($form_values[$field]);
+        unset($form_state['values'][$field]);
       }
       $types = node_get_types();
-      if ($types[$form_values['type']]) {
-        variable_set('nodeformtemplate_' . $form_values['type'], serialize($form_values));
-        drupal_set_message(t('Template saved'));
+      if ($types[$form_state['values']['type']]) {
+        variable_set('nodeformtemplate_'. $form_state['values']['type'], serialize($form_state['values']));
+        drupal_set_message(t('The template for %type nodes has been saved.',
+          array('%type' => $form_state['values']['type'])));
       }
     break;
 
     case t('Reset'):
       $types = node_get_types();
-      if ($types[$form_values['type']]) {
-        variable_del('nodeformtemplate_' . $form_values['type']);
-        drupal_set_message(t('Template cleared'));
+      if ($types[$form_state['values']['type']]) {
+        variable_del('nodeformtemplate_'. $form_state['values']['type']);
+        drupal_set_message(t('The template for %type nodes has been cleared.',
+          array('%type' => $form_state['values']['type'])));
       }
     break;
   }
@@ -147,8 +156,8 @@
 function nodeformtemplate_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
   switch ($op) {
     case 'prepare':
-      if (!$node->nid && variable_get('nodeformtemplate_' . $node->type, 0)) {
-        $template = unserialize(variable_get('nodeformtemplate_' . $node->type, 0));
+      if (!$node->nid && variable_get('nodeformtemplate_'. $node->type, 0)) {
+        $template = unserialize(variable_get('nodeformtemplate_'. $node->type, 0));
 
         // Don't do if we are on the form template settings page
         if (!$node->formtemplate_settings) {
@@ -179,7 +188,7 @@
       // try to insert query parameters if a placeholder is found
       foreach ($_GET as $key => $var) {
         if ($var != '') {
-          $template[$field] = str_replace('%' . $key, $var, $template[$field]);
+          $template[$field] = str_replace('%'. $key, $var, $template[$field]);
         }
       }
       // clean remaining placeholders
Index: nodeformtemplate.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodeformtemplate/nodeformtemplate.info,v
retrieving revision 1.1
diff -u -r1.1 nodeformtemplate.info
--- nodeformtemplate.info	2 Jan 2007 16:26:52 -0000	1.1
+++ nodeformtemplate.info	13 Mar 2009 04:02:30 -0000
@@ -1,3 +1,4 @@
-; $Id: nodeformtemplate.info,v 1.1 2007/01/02 16:26:52 egonbianchet Exp $
+; $Id$
 name = Nodeformtemplate
 description = Allow users to configure a default template for each node type.
+core = 6.x
\ No newline at end of file
