My aim is to create a new menu item and display the user profile form on that page.
Here is the code I am using.
/**
* Implements hook_menu().
*
*/
function profile_preferences_menu(){
$items['user/%/edit/profile-preferences'] = array(
'title' => t('Profile Preferences'),
'page callback' => '_profile_preference_display_preference',
'page arguments' => array(1),
'access arguments' => array('access profile preferences'),
'type' => MENU_LOCAL_TASK,
'weight' => '0'
);
return $items;
}
/**
* Implementation of hook_permission().
*/
function profile_preferences_permission() {
return array(
'access profile preferences' => array(
'title' => t('Access List of profile preferences'),
'description' => t('Access permission to view all the profile preferences.')
),
);
}
/**
* Function to fetch and display preferences form.
*/
function _profile_preference_display_preference() {
global $user;
module_load_include('inc', 'user', 'user.pages');
$form = drupal_get_form('user_profile_form', $user, 'account');
unset($form['account']);
return $form;
}
When I access it using the administrator account, it works perfectly; when I access using another user account (who has the required permission) it gives me the following error.
I wonder if there is any issue with the implementation of hook_menu()
.
t()
; that is automatically done by Drupal core code. – kiamlaluno♦ May 15 at 8:18unset($form['account']);
. That should fix the warning – Clive♦ May 15 at 8:21