array_flip() error while creating a menu item with form 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' =&gt; t('Profile Preferences'),
        'page callback' =&gt; '_profile_preference_display_preference',
        'page arguments' =&gt; array(1),
        'access arguments' =&gt; array('access profile preferences'),
        'type' =&gt; MENU_LOCAL_TASK,
        'weight' =&gt; '0'
    );
    return $items;
}

/**
 * Implementation of hook_permission().
 */
function profile_preferences_permission() {
    return array(
        'access profile preferences' =&gt;  array(
            'title' =&gt; t('Access List of profile preferences'),
            'description' =&gt; 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().
The code that is causing the error is the following one, executed from DrupalDefaultEntityController::load().

  // Create a new variable which is either a prepared version of the $ids
  // array for later comparison with the entity cache, or FALSE if no $ids
  // were passed. The $ids array is reduced as items are loaded from cache,
  // and we need to know if it's empty for this reason to avoid querying the
  // database when all requested entities are loaded from cache.
  $passed_ids = !empty($ids) ? array_flip($ids) : FALSE;


I could not track down which function is calling user_load() or a similar function to load a user entity. As far as I can see, the form validation and form submission handlers added to the form use $form['#user'] or $form_state['user'] (which is set from the $account parameter passed to user_profile_form()). Keep in mind that $form and $form_state are used when saving the entity, such as in the following function call done from user_profile_form_submit().

entity_form_submit_build_entity('user', $account, $form, $form_state);


It is always a bad idea to unset a form item, as that would be causing problems with the code that expects those form items to be present.
Removing them, you are also avoiding that the corresponding items in $form_state['values'] are present. This is probably causing the error you see.

As side note, your page callback is getting a parameter, but that is not used. Instead, your code is using the global user object, which means the shown form is for the currently logged in user, not for the user whose ID is passed in the URL.

I would also change user/%/edit/profile-preferences with user/%user/edit/profile-preferences. The latter automatically validates the user ID and loads the user object, which is then passed to the page callback.