I have been struggling with this. Views cannot help me (or I didn't figure out how).
I have created a new tab to my profile 2 in my custom module using custom_menu custom_menu_alter custom_menu_local_tasks_alter
The URL is mywebsite.com/profile-main/%user/preferences
Preferences is the new URL linked to the new tab.
My aim is to display a field group with a bunch of preferences info in that new tab/URL Technically under that tab I want the user to log any preferences they have regarding newsletters and how we contact them etc...(GDPR related stuff) I need the data to be attached to the specific user.
I can't seem to figure it out. I am not very confident with hooks and custom code and at this point I am stuck. What did I miss?
Any clue on how I could achieve this?
I am using Drupal 7. What I want is to move fields (in a field group) from the main profile 2 registration page form and display them in the new tab accessible when logged in to profile 2 account, instead of having everything in the same form. But I am happy to have to create a different form if it would work better. This is what's returned by custom menu:
$items['profile-main/%user/preferences'] = array(
'title' => t(' Preferences'),
'page callback' => 'custom_user_preferences',
'page arguments' => array(1), // Uid
'access callback' => TRUE,
'access arguments' => array('access candidate_dashboard'),
'type' => MENU_LOCAL_TASK,
);
This is the array for custom_user_preferences:
'custom_user_preferences' => array(
'file' => 'includes/user_preferences.inc',
'template' => 'templates/user_preferences',
'variables' => array(
'profile' => NULL,
'approved' => NULL,
'cust_type' => NULL,
)
),
edit: Am I right to assume that I have to
- programmatically create a form
- which upon submission saves the data in relevant profile2 fields
- display the form in the new path I created
edit 11/jan
In the end I am creating a form as the fields I need to add are not in the profile 2 set up to start with (the profile 2 registration form has more than 180 fields in it). I've been receiving error:
*Warning: Illegal string offset '#tree' in form_builder() (line 1891 of /**/**/**/site/includes/form.inc).
Warning: Illegal string offset '#tree' in form_builder() (line 1911 of /**/**/**/site/includes/form.inc).
Warning: Illegal string offset '#parents' in form_builder() (line 1911 of /**/**/**/site/includes/form.inc).
Notice: Array to string conversion in form_builder() (line 1911 of /**/**/**/site/includes/form.inc).
Warning: Illegal string offset '#array_parents' in form_builder() (line 1916 of /**/**/**/site/includes/form.inc).
Notice: Array to string conversion in form_builder() (line 1916 of /**/**/**/site/includes/form.inc).
Warning: Illegal string offset '#weight' in form_builder() (line 1920 of /**/**/**/site/includes/form.inc).
Warning: Illegal string offset '#processed' in form_builder() (line 1802 of /**/**/**/site/includes/form.inc).
Error: Unsupported operand types in form_builder() (line 1812 of /**/**/**/site/includes/form.inc).*
I am not sure if the problem is my form or the callback or something else...
function site_menu() {
$items = array();
$items['profile-main/%user/preferences'] = array(
'title' => t(' Preferences'),
'page callback' => drupal_get_form,
'page arguments' => array('site_upload_form', 1), // Uid
'access callback' => TRUE,
'access arguments' => array('access content'),
'type' => MENU_LOCAL_TASK,
);
}
function site_upload_form($form, &$form_state){
$form['email']= array(
'#type'=>'textfield',
'#title'=>t('Confirm email address'),
'#maxlength'=> 255,
'#required'=> TRUE,
);
$form['frequencyemail']= array(
'#type'=>'select',
'#title'=> t('How often do you want to hear from us?'),
'#options'=> array(
0 =>'Regularly',
1 => 'Quarterly',
2 => 'During the Summit',
3 => 'Never',
),
'#required'=> TRUE,
);
$form['submit']= array(
'#type'=>'submit',
'#value'=> t('Submit'),
);
return $form;
}
Not sure what I am looking for
/profile-main/%user/preferences
, but not quite sure. In yourcustom_menu
what are you returning for that path?