? bio-fields-on-registration-182266.patch
? bio.module-151572.patch
Index: bio.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/bio/bio.module,v
retrieving revision 1.2.2.12
diff -u -p -r1.2.2.12 bio.module
--- bio.module	3 Jul 2007 18:28:09 -0000	1.2.2.12
+++ bio.module	29 Nov 2007 07:16:07 -0000
@@ -79,6 +79,30 @@ function bio_form_alter($form_id, &$form
       $form['author']['name']['#description'] = t(' This field is disabled. You cannot alter the author of this entry from within the user area.');
     }
   }
+
+  // Display CCK fields on the user registration form, if they've been
+  // marked as such.
+  if ($form_id == 'user_register' && variable_get('bio_registration_fields', 0)) {
+    $type_name = variable_get('bio_nodetype', 'bio');
+    $widget_types = _content_widget_types();
+    $fields = _bio_get_fields();
+
+    foreach ($fields as $field_name => $field) {
+      if (variable_get("bio_registration_$field_name", 0)) {
+        // Create a dummy node.
+        $node = new stdClass();
+        $node->type = $type_name;
+
+        // Figure out what widget function to call.
+        $module = $widget_types[$field['widget']['type']]['module'];
+        $function = $module .'_widget';
+
+        // Get the form field.
+        $op = 'form';
+        $form[$field_name] = $function($op, $node, $field, $node_field);
+      }
+    }
+  }
 }
 
 function bio_profile_alter(&$account, &$fields) {
@@ -167,7 +191,7 @@ function bio_link($type, $node = NULL, $
         'attributes' => array('title' => t('View @user\'s @bio.', array('@user' => $user->name, '@bio' => node_get_types('name', variable_get('bio_nodetype', 'bio')))))));
     }
   } 
-} 
+}
 
 /**
  * Return node id of the bio for a given user
@@ -222,11 +246,49 @@ function bio_settings() {
     '#description' => t('Display nothing but the bio node on the user profile page.'),
     '#default_value' => variable_get('bio_profile_takeover', 0),
   );
+
+  // Add additional field options.
+  $form['bio_field_options'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Additional field options'),
+    '#collapsible' => TRUE,
+    '#theme' => 'bio_field_options',
+  );
+  $fields = _bio_get_fields();
+  foreach ($fields as $field_name => $properties) {
+    $form['bio_field_options'][$field_name]['name'] = array(
+      '#value' => check_plain($field_name),
+    );
+    $form['bio_field_options'][$field_name]["bio_registration_$field_name"] = array(
+      '#type' => 'checkbox',
+      '#default_value' => variable_get("bio_registration_$field_name", 0),
+    );
+  }
+
   $add_a_submit = system_settings_form($form);
   $add_a_submit['#validate']['bio_settings_validate_xxx'] = array();
   return $add_a_submit;
 }
 
+/**
+ * Format field options from Bio settings form in a table.
+ * 
+ * @ingroup themeable
+ */
+function theme_bio_field_options($form) {
+  $rows = array();
+  $header = array(t('Field'), t('Show on registration form'));
+
+  foreach (element_children($form) as $field_name) {
+    $row = array();
+    $row[] = drupal_render($form[$field_name]['name']);
+    $row[] = drupal_render($form[$field_name]["bio_registration_$field_name"]);
+    $rows[] = $row;
+  }
+
+  return theme('table', $header, $rows);
+}
+
 /*
  * A submit handler for the bio settings page so that we can invalidate the views
  * cache in case the bio node type changed. We need the _xxx suffix to keep it
@@ -234,7 +296,32 @@ function bio_settings() {
  * validate phase because submits were interfering with the #base attribute. Yuck.
  */
 function bio_settings_validate_xxx($form_id, $form_values) {
-  views_invalidate_cache();
+  // If any fields are set to be visible on the user registration form,
+  // set a global variable indicating such that can be checked later.
+  $bio_registration_fields = FALSE;
+
+  $fields = _bio_get_fields();
+  foreach ($fields as $field_name => $properties) {
+    if ($form_values["bio_registration_$field_name"]) {
+      $bio_registration_fields = TRUE;
+      break;
+    }
+  }
+  variable_set('bio_registration_fields', $bio_registration_fields);
+
+  // Invalidate views cache, in case bio node type has changed.
+  if (module_exists('views')) {
+    views_invalidate_cache();
+  }
+}
+
+/**
+ * Retrieve field info for bio CCK type.
+ */
+function _bio_get_fields() {
+  $bio_nodetype = variable_get('bio_nodetype', 'bio');
+  $type = content_types($bio_nodetype);
+  return $type['fields'];
 }
 
 /**
