? user_profile_form.patch Index: modules/content_profile_registration.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/content_profile/modules/Attic/content_profile_registration.module,v retrieving revision 1.1.2.36 diff -u -p -r1.1.2.36 content_profile_registration.module --- modules/content_profile_registration.module 26 Mar 2010 16:32:28 -0000 1.1.2.36 +++ modules/content_profile_registration.module 4 Aug 2010 18:57:06 -0000 @@ -22,6 +22,18 @@ function content_profile_registration_fo content_profile_registration_add_profile_form($type, $form, $form_state); } } + else if ($form_id == 'user_profile_form' && $form['_category']['#value'] == 'account') { + require_once drupal_get_path('module', 'node') .'/node.pages.inc'; + + // Allow other modules to customize the used profile types, so modules + // can easily customize the registration form. + $default_types = content_profile_get_types('names', 'user_profile_form'); + $form += array('#content_profile_registration_use_types' => $default_types); + foreach ($form['#content_profile_registration_use_types'] as $type => $typename) { + $node = content_profile_load($type, $form['#uid']); + unidesk_content_profile_registration_add_profile_form($type, $form, $form_state, $node); + } + } elseif ($form_id == 'content_profile_admin_settings') { $type = $form_state['type']; // Let other modules add registration child elements before us! @@ -32,6 +44,12 @@ function content_profile_registration_fo '#description' => t('Customize how this content profile shows up on the user registration page.'), '#collapsible' => TRUE, ); + $form['registration']['user_profile_form'] = array( + '#type' => 'checkbox', + '#title' => t('Use on Account edit'), + '#description' => t('Use this content type on the user edit page'), + '#default_value' => content_profile_get_settings($type, 'user_profile_form'), + ); $form['registration']['registration_use'] = array( '#type' => 'checkbox', '#title' => t('Use on Registration'), @@ -103,9 +121,11 @@ function _content_profile_registration_g * @see content_profile_registration_user_register_validate() * @see content_profile_registration_user_register_submit() */ -function content_profile_registration_add_profile_form($type, &$form, &$form_state) { +function content_profile_registration_add_profile_form($type, &$form, &$form_state, $node = NULL) { // Initialize new node and add in its form. - $node = array('uid' => 0, 'name' => '', 'type' => $type); + if (empty($node)) { + $node = (object) array('uid' => 0, 'name' => '', 'type' => $type); + } // Get the original node form. $node_form = drupal_retrieve_form($type .'_node_form', $form_state, $node); drupal_prepare_form($type .'_node_form', $node_form, $form_state); @@ -115,24 +135,23 @@ function content_profile_registration_ad // If non-CCK form elements are hidden, only copy over the CCK stuff if (in_array('other', content_profile_get_settings($type, 'registration_hide'))) { - foreach ($node_form['#field_info'] as $field_name => $info) { - if (isset($node_form[$field_name])) { - $form_add[$field_name] = $node_form[$field_name]; - } - } + $fields_move = array_merge( + array_keys($node_form['#field_info']), + array( + 'title', + '#node', + 'type', + 'nid', + 'vid', + ) + ); // Copy over any fieldgroups $keys = array_keys($node_form); foreach ($keys as $key) { - if (stristr($key, 'group_')) { + if (in_array($key, $fields_move) || stristr($key, 'group_')) { $form_add[$key] = $node_form[$key]; } } - // Add the title - $form_add['title'] = $node_form['title']; - - // Set this to the values of one node, as it might be need by some #ahah callbacks - $form_add['#node'] = $node_form['#node']; - $form_add['type'] = $node_form['type']; } else { foreach (array('uid', 'name', 'author', 'buttons', 'language', '#theme', 'options') as $key) { @@ -160,8 +179,15 @@ function content_profile_registration_ad $form += $form_add; // Add in further callbacks needed, if not yet done. - if (!isset($form['#content_profile_weights'])) { + if ($form['form_id']['#value'] == 'user_profile_form') { + $form['#submit'][] = 'content_profile_registration_user_edit_submit'; + $form['#submit'] = array_diff($form['#submit'], array('content_profile_registration_user_register_submit')); + } + elseif (!isset($form['#content_profile_weights'])) { $form['#submit'][] = 'content_profile_registration_user_register_submit'; + } + + if (!isset($form['#content_profile_weights'])) { $form['#validate'][] = 'content_profile_registration_user_register_validate'; $form['#pre_render'][] = 'content_profile_registration_alter_weights'; } @@ -180,6 +206,7 @@ function content_profile_registration_ad } } + /** * Pre render callback that makes sure our elements are grouped together. * The ordering in between the single elements is kept. @@ -266,12 +293,29 @@ function content_profile_registration_us } /** + * Submits the user edit form + */ +function content_profile_registration_user_edit_submit($form, &$form_state) { + foreach ($form['#content_profile_registration_use_types'] as $type => $typename) { + if ($node = &$form_state['content_profile_registration'][$type]['node']) { + // Set user's information for the node. + $node->uid = $node->_account->uid; + $node->name = $node->_account->name; + // Update + $node = node_submit($node); + node_save($node); + } + } +} + +/** * Implementation of hook_content_profile_settings(). */ function content_profile_registration_content_profile_settings() { return array( 'registration_use' => FALSE, 'admin_user_create_use' => FALSE, + 'user_profile_form' => FALSE, 'registration_hide' => array(), ); }