Disable user language setting in user-edit page I want to unset this specific part of the settings form in template php. I found some code example for Drupal 6, but can't figure out how to do it in Drupal 7.

I tried this without result:

if ($form_id == 'user_profile_form') {
  unset($form['language']);
}


(There is a module "user tweaks" but I want it to do it in the preprocess)
I created both the mentioned projects and I have maintained them for a while. (I stopped maintaining Drupal 6 and 7 modules.)

The code used in the Disable user language module is not correct: unset() should never be used for form elements, as this would cause problems to modules that try to access the form element.

The correct code is the following one. It would preferable if the code would be executed after other modules execute their own code.

/**
 * Implements hook_form_alter().
 */
function mytheme_form_alter(&amp;$form, $form_state, $form_id) {
  // The language selector is only displayed if there is more than one language.
  if (drupal_multilingual()) {
    if ($form_id == 'user_register_form' || ($form_id == 'user_profile_form' &amp;&amp; $form['#user_category'] == 'account')) {
      if (count(element_children($form['locale'])) &gt; 1) {
        $form['locale']['language']['#access'] = FALSE;
      }
      else {
        $form['locale']['#access'] = FALSE;
      }
    }
  }
}


In my module I also used hook_init() to change $user-&gt;language to a default value; differently $user-&gt;language would have the last value saved.

/**
 * Implements hook_init().
 */
function dul_init() {
  if (!user_access('change own user language')) {
    global $user;

    $user-&gt;language = language_default('language');
  }
}


Clearly, the Disable user language module has its own permission, which allows to select which users have the permission to select their own language, but that part is not strictly necessary.

I used hook_init() because the documentation for hook_user_load() has the following warning:


  Due to the static cache in user_load_multiple() you should not use this hook to modify the user properties returned by the {users} table itself since this may result in unreliable results when loading from cache.


The code is also changing on the fly a property for the currently logged-in user, without making any changes in the database. hook_user_load() would not serve this purpose, since it is invoked any time a module calls user_load().