Drupal 7 – Menu item is disabled after saving the node in different language

i found a bug with the i18n module. Assume i have a node in Traditional Chinese and i edit it in English. The menu item set Menu settings will be disabled after save.

A simple workaround is to alter the node edit form such that the user will be redirected to the language same as the node.

function <module>_form_alter(&$form, $form_state, $form_id) {
  if(preg_match('/^.*_node_form$/', $form_id)) {
    // check if the backend language is the same as the node language
    global $language;
    if(isset($form['#node']) && $form['#node']->type == 'page' && $language->language != $form['#node']->language) {
      $node = $form['#node'];
      
      //Get the list of language objects
      $languages = language_list();
      
      //Get the object and set the global $language;
      $language = $languages[$node->language];
      
      //Redirection
      $destination = array('destination' => $_GET['destination']);
      unset($_GET['destination']);
      drupal_goto("node/{$node->nid}/edit", array('language' => $language, 'query' => $destination));
    }
  }
}

Done =)

Reference: Drupal i18n issues – Disabled menu items

Advertisement

2 thoughts on “Drupal 7 – Menu item is disabled after saving the node in different language”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.