Index: bio.module =================================================================== --- bio.module (Revision 275) +++ bio.module (Arbeitskopie) @@ -87,7 +87,7 @@ function bio_menu($may_cache) { * Implementation of hook_form_alter(). */ function bio_form_alter($form_id, &$form) { - if ($form_id == bio_get_type() .'_node_form' && arg(0) == 'user') { + if (arg(0) == 'user' && $form_id == bio_get_type() .'_node_form' && (!variable_get('bio_edit_form', 0) || !module_exists('subform_element'))) { // We're editing the bio in the user area... be sure we end up here when we // finish submission, and disallow changing the author. $account = user_load(array('uid' => arg(1))); @@ -266,7 +266,7 @@ function bio_nodeapi(&$node, $op, $a3 = */ function bio_user($op, &$edit, &$account, $category = NULL) { // If there's no bio for this user, nothing to do here. - if ($op != 'register' && $op != 'insert' && !$nid = bio_for_user($account->uid)) { + if ($op == 'view' && !$nid = bio_for_user($account->uid)) { return; } @@ -298,11 +298,39 @@ function bio_user($op, &$edit, &$account // Display CCK fields on the user registration form, if they've been // marked as such. return bio_user_register_form(); - break; + + case 'form': + // Display bio node form on user account form, if enabled. + if (!variable_get('bio_edit_form', 0) || !module_exists('subform_element')) { + return; + } + $type = bio_get_type(); + // Edit existing bio node. + if ($nid = bio_for_user($account->uid)) { + $node = node_load($nid); + $access = node_access('update', $node); + } + // Create new bio node. + else { + $node = (object)array('type' => $type, 'uid' => $account->uid, 'name' => $account->name); + $access = ($user->uid == $account->uid && node_access('create', $type)) || user_access('administer nodes'); + } + if ($access) { + $form['bio_node'] = array( + '#type' => 'subform', + '#id' => $type .'_node_form', + '#arguments' => array($node), + '#data_separation' => TRUE, + '#weight' => 20, + '#extra_form' => array('preview' => array('#access' => FALSE), 'submit' => array('#access' => FALSE), 'delete' => array('#access' => FALSE)), + ); + // Prepend subform_element form submit handler for bio node. + $form['#submit'] = array('subform_element_submit' => array()) + (array)$form['#submit']; + } + return $form; case 'insert': return bio_user_register_submit($edit); - break; } } @@ -337,12 +365,18 @@ function bio_link($type, $node = NULL, $ * Node ID of bio, or FALSE if no bio node was found. */ function bio_for_user($uid = NULL) { + static $nid; + + if (isset($nid)) { + return $nid; + } if (is_null($uid)) { global $user; $uid = $user->uid; } - return db_result(db_query('SELECT nid FROM {bio} WHERE uid = %d', $uid)); + $nid = db_result(db_query('SELECT nid FROM {bio} WHERE uid = %d', $uid)); + return $nid; } /** @@ -384,13 +418,24 @@ function bio_settings() { '#description' => t('Display nothing but the bio node on the user profile page.'), '#default_value' => variable_get('bio_profile_takeover', 0), ); + $form['bio_edit_form'] = array( + '#type' => 'checkbox', + '#title' => t('Show fields on user account edit form'), + '#return_value' => 1, + '#default_value' => variable_get('bio_edit_form', 0), + '#description' => t('Enable this option to display bio fields on the user account edit form. This will automatically create or update a bio record for a user when they edit their user account.'), + ); + if (!module_exists('subform_element')) { + $form['bio_edit_form']['#disabled'] = TRUE; + $form['bio_edit_form']['#description'] .= '
'. t('This feature requires the Subform Element module.', array('!subform-link' => 'http://drupal.org/project/subform_element')); + } // Show fields on the registration form. if (module_exists('content')) { $form['bio_regstration_form'] = array( - '#type' => 'radios', + '#type' => 'checkbox', '#title' => t('Show fields on registration form'), - '#options' => array(t('Disabled'), t('Enabled')), + '#return_value' => 1, '#default_value' => variable_get('bio_regstration_form', 0), '#description' => t('Enable this option to display bio fields on the user registration form. This will automatically create a bio record for a user when they register.'), );