Custom user data tab not displayed with hook_user
I took over a site that has custom user data stored in a separate table, and I would like to display those fields in a separate tab in the user profile. I figured I could just write a page and form function, but I'd like to integrate it with user data. I have the following hook_user implementation: function hsi_user($op, &$edit, &$account, $category = NULL) { switch ($op) { case 'categories': $data[] = array( 'name' => 'hsi_demo', 'title' => 'Demographics', 'weight' => 3, 'access callback' => TRUE, ); return $data; case 'form': $data = db_fetch_object(db_query("SELECT bday, gender, nation, religion, heard FROM hsi_demo WHERE uid = %d", $account->uid)); $countries = _hsi_countries(); $fields['hsi_demo']['bday'] = array( '#type' => 'date', '#title' => 'Birth Date', '#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '', '#required' => TRUE, ); $fields['hsi_demo']['gender'] = array( '#type' => 'select', '#title' => 'Gender', '#options' => array('m' => 'Male', 'f' => 'Female'), '#default_value' => $data->gender, ); $fields['hsi_demo']['nation'] = array( '#type' => 'select', '#title' => 'Country', '#options' => $countries, '#default_value' => $data->nation, ); $fields['hsi_demo']['denomination'] = array( '#type' => 'select', '#title' => 'Denomination', '#options' => $countries, '#default_value' => $data->denomination, '#options' => $denominations, ); return $fields; } } The problem is, I don't get my Demographics tab displayed. Do I also need a hook_menu entry for this path (i.e. user/%user/edit/hsi_demo)? What else am I missing? Thanks. Steve
Hi Steve The user module handles the hook_menu for user categories defined through hook_user. Perhaps the access callback/access arguments are the issue? Lee -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Steve Edwards Sent: Wednesday, 3 March 2010 6:11 AM To: Drupal Development Subject: [development] Custom user data tab not displayed with hook_user I took over a site that has custom user data stored in a separate table, and I would like to display those fields in a separate tab in the user profile. I figured I could just write a page and form function, but I'd like to integrate it with user data. I have the following hook_user implementation: function hsi_user($op, &$edit, &$account, $category = NULL) { switch ($op) { case 'categories': $data[] = array( 'name' => 'hsi_demo', 'title' => 'Demographics', 'weight' => 3, 'access callback' => TRUE, ); return $data; case 'form': $data = db_fetch_object(db_query("SELECT bday, gender, nation, religion, heard FROM hsi_demo WHERE uid = %d", $account->uid)); $countries = _hsi_countries(); $fields['hsi_demo']['bday'] = array( '#type' => 'date', '#title' => 'Birth Date', '#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '', '#required' => TRUE, ); $fields['hsi_demo']['gender'] = array( '#type' => 'select', '#title' => 'Gender', '#options' => array('m' => 'Male', 'f' => 'Female'), '#default_value' => $data->gender, ); $fields['hsi_demo']['nation'] = array( '#type' => 'select', '#title' => 'Country', '#options' => $countries, '#default_value' => $data->nation, ); $fields['hsi_demo']['denomination'] = array( '#type' => 'select', '#title' => 'Denomination', '#options' => $countries, '#default_value' => $data->denomination, '#options' => $denominations, ); return $fields; } } The problem is, I don't get my Demographics tab displayed. Do I also need a hook_menu entry for this path (i.e. user/%user/edit/hsi_demo)? What else am I missing? Thanks. Steve= Internal Virus Database is out of date. Checked by AVG - www.avg.com Version: 8.5.406 / Virus Database: 271.1.1/2686 - Release Date: 02/13/10 19:35:00
Categories display as secondary tasks under the Edit tab. If you want a primary tab on top then yeah - you need to do a new menu hook like /user/%user/demographics with the type set to MENU_LOCAL_TASK Jamie Holly http://www.intoxination.net http://www.hollyit.net On 3/2/2010 3:10 PM, Steve Edwards wrote:
I took over a site that has custom user data stored in a separate table, and I would like to display those fields in a separate tab in the user profile. I figured I could just write a page and form function, but I'd like to integrate it with user data. I have the following hook_user implementation:
function hsi_user($op,&$edit,&$account, $category = NULL) { switch ($op) { case 'categories': $data[] = array( 'name' => 'hsi_demo', 'title' => 'Demographics', 'weight' => 3, 'access callback' => TRUE, ); return $data; case 'form': $data = db_fetch_object(db_query("SELECT bday, gender, nation, religion, heard FROM hsi_demo WHERE uid = %d", $account->uid)); $countries = _hsi_countries();
$fields['hsi_demo']['bday'] = array( '#type' => 'date', '#title' => 'Birth Date', '#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '', '#required' => TRUE, ); $fields['hsi_demo']['gender'] = array( '#type' => 'select', '#title' => 'Gender', '#options' => array('m' => 'Male', 'f' => 'Female'), '#default_value' => $data->gender, ); $fields['hsi_demo']['nation'] = array( '#type' => 'select', '#title' => 'Country', '#options' => $countries, '#default_value' => $data->nation, ); $fields['hsi_demo']['denomination'] = array( '#type' => 'select', '#title' => 'Denomination', '#options' => $countries, '#default_value' => $data->denomination, '#options' => $denominations, ); return $fields; } }
The problem is, I don't get my Demographics tab displayed. Do I also need a hook_menu entry for this path (i.e. user/%user/edit/hsi_demo)? What else am I missing?
Thanks.
Steve
All I want is it to display as a secondary tab, but I can't even get that to show up. Is the code below sufficient to make that happen, or am I missing something else? Thanks. Steve On Mar 2, 2010, at 3:39 PM, Jamie Holly wrote:
Categories display as secondary tasks under the Edit tab. If you want a primary tab on top then yeah - you need to do a new menu hook like /user/%user/demographics with the type set to MENU_LOCAL_TASK
Jamie Holly http://www.intoxination.net http://www.hollyit.net
On 3/2/2010 3:10 PM, Steve Edwards wrote:
I took over a site that has custom user data stored in a separate table, and I would like to display those fields in a separate tab in the user profile. I figured I could just write a page and form function, but I'd like to integrate it with user data. I have the following hook_user implementation:
function hsi_user($op,&$edit,&$account, $category = NULL) { switch ($op) { case 'categories': $data[] = array( 'name' => 'hsi_demo', 'title' => 'Demographics', 'weight' => 3, 'access callback' => TRUE, ); return $data; case 'form': $data = db_fetch_object(db_query("SELECT bday, gender, nation, religion, heard FROM hsi_demo WHERE uid = %d", $account->uid)); $countries = _hsi_countries();
$fields['hsi_demo']['bday'] = array( '#type' => 'date', '#title' => 'Birth Date', '#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '', '#required' => TRUE, ); $fields['hsi_demo']['gender'] = array( '#type' => 'select', '#title' => 'Gender', '#options' => array('m' => 'Male', 'f' => 'Female'), '#default_value' => $data->gender, ); $fields['hsi_demo']['nation'] = array( '#type' => 'select', '#title' => 'Country', '#options' => $countries, '#default_value' => $data->nation, ); $fields['hsi_demo']['denomination'] = array( '#type' => 'select', '#title' => 'Denomination', '#options' => $countries, '#default_value' => $data->denomination, '#options' => $denominations, ); return $fields; } }
The problem is, I don't get my Demographics tab displayed. Do I also need a hook_menu entry for this path (i.e. user/%user/edit/hsi_demo)? What else am I missing?
Thanks.
Steve
Yup, but you don't need the access callback, only name, title and weight: http://api.drupal.org/api/function/hook_user Also for your form op you should wrap that in an if block case 'form': if ($category=='hsi_demo'){ //form code } break; Jamie Holly http://www.intoxination.net http://www.hollyit.net On 3/3/2010 10:40 AM, Steve Edwards wrote:
All I want is it to display as a secondary tab, but I can't even get that to show up. Is the code below sufficient to make that happen, or am I missing something else?
Thanks.
Steve
On Mar 2, 2010, at 3:39 PM, Jamie Holly wrote:
Categories display as secondary tasks under the Edit tab. If you want a primary tab on top then yeah - you need to do a new menu hook like /user/%user/demographics with the type set to MENU_LOCAL_TASK
Jamie Holly http://www.intoxination.net http://www.hollyit.net
On 3/2/2010 3:10 PM, Steve Edwards wrote:
I took over a site that has custom user data stored in a separate table, and I would like to display those fields in a separate tab in the user profile. I figured I could just write a page and form function, but I'd like to integrate it with user data. I have the following hook_user implementation:
function hsi_user($op,&$edit,&$account, $category = NULL) { switch ($op) { case 'categories': $data[] = array( 'name' => 'hsi_demo', 'title' => 'Demographics', 'weight' => 3, 'access callback' => TRUE, ); return $data; case 'form': $data = db_fetch_object(db_query("SELECT bday, gender, nation, religion, heard FROM hsi_demo WHERE uid = %d", $account->uid)); $countries = _hsi_countries();
$fields['hsi_demo']['bday'] = array( '#type' => 'date', '#title' => 'Birth Date', '#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '', '#required' => TRUE, ); $fields['hsi_demo']['gender'] = array( '#type' => 'select', '#title' => 'Gender', '#options' => array('m' => 'Male', 'f' => 'Female'), '#default_value' => $data->gender, ); $fields['hsi_demo']['nation'] = array( '#type' => 'select', '#title' => 'Country', '#options' => $countries, '#default_value' => $data->nation, ); $fields['hsi_demo']['denomination'] = array( '#type' => 'select', '#title' => 'Denomination', '#options' => $countries, '#default_value' => $data->denomination, '#options' => $denominations, ); return $fields; } }
The problem is, I don't get my Demographics tab displayed. Do I also need a hook_menu entry for this path (i.e. user/%user/edit/hsi_demo)? What else am I missing?
Thanks.
Steve
participants (3)
-
Jamie Holly -
Lee Rowlands -
Steve Edwards