From 6e431c53b34fa322aa7d1c61fe472e130302ea64 Mon Sep 17 00:00:00 2001
From: Dries <dries@buytaert.net>
Date: Thu, 16 Feb 2012 10:52:30 -0500
Subject: [PATCH] =?UTF-8?q?-=20Patch=20#540294=20by=20G=C3=A1bor=20Hojtsy,?=
 =?UTF-8?q?=20clemens.tolboom,=20Xano:=20node=20language=20settings=20from?=
 =?UTF-8?q?=20Locale=20to=20Node=20module.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 core/modules/comment/comment.module           |  2 +-
 core/modules/field/modules/text/text.test     |  2 +-
 core/modules/locale/locale.module             | 47 -------------------
 core/modules/locale/locale.test               | 14 ++----
 core/modules/node/content_types.inc           |  8 ++++
 core/modules/node/node.install                | 17 +++++++
 core/modules/node/node.pages.inc              | 23 +++++++++
 core/modules/path/path.test                   |  2 +-
 core/modules/poll/poll.test                   |  2 +-
 .../upgrade/drupal-7.language.database.php    |  4 ++
 .../tests/upgrade/upgrade.language.test       |  6 +++
 core/modules/translation/translation.module   |  9 ++--
 core/modules/translation/translation.test     |  4 +-
 13 files changed, 74 insertions(+), 66 deletions(-)

diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 70218a52e600..4acbe6d2761b 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -1841,7 +1841,7 @@ function comment_form($form, &$form_state, $comment) {
   // If a content type has multilingual support we set the comment to inherit the
   // content language. Otherwise mark the comment as language neutral.
   $comment_langcode = $comment->language;
-  if (($comment_langcode == LANGUAGE_NONE) && variable_get('language_content_type_' . $node->type, 0)) {
+  if (($comment_langcode == LANGUAGE_NONE) && variable_get('node_type_language_' . $node->type, 0)) {
     $comment_langcode = $language_content->langcode;
   }
   $form['language'] = array(
diff --git a/core/modules/field/modules/text/text.test b/core/modules/field/modules/text/text.test
index 59369370efcc..979079ac11ab 100644
--- a/core/modules/field/modules/text/text.test
+++ b/core/modules/field/modules/text/text.test
@@ -434,7 +434,7 @@ class TextTranslationTestCase extends DrupalWebTestCase {
     $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
 
     // Set "Article" content type to use multilingual support with translation.
-    $edit = array('language_content_type' => 2);
+    $edit = array('node_type_language' => TRANSLATION_ENABLED);
     $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));
     $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Article')), t('Article content type has been updated.'));
   }
diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module
index 573139386a5c..d50684e02e4b 100644
--- a/core/modules/locale/locale.module
+++ b/core/modules/locale/locale.module
@@ -246,31 +246,6 @@ function locale_language_selector_form($user) {
   return $form;
 }
 
-/**
- * Implements hook_form_FORM_ID_alter().
- */
-function locale_form_node_type_form_alter(&$form, &$form_state) {
-  if (isset($form['type'])) {
-    $form['workflow']['language_content_type'] = array(
-      '#type' => 'radios',
-      '#title' => t('Multilingual support'),
-      '#default_value' => variable_get('language_content_type_' . $form['#node_type']->type, 0),
-      '#options' => array(t('Disabled'), t('Enabled')),
-      '#description' => t('Enable multilingual support for this content type. If enabled, a language selection field will be added to the editing form, allowing you to select from one of the <a href="!languages">enabled languages</a>. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('!languages' => url('admin/config/regional/language'))),
-    );
-  }
-}
-
-/**
- * Return whether the given content type has multilingual support.
- *
- * @return
- *   True if multilingual support is enabled.
- */
-function locale_multilingual_node_type($type_name) {
-  return (bool) variable_get('language_content_type_' . $type_name, 0);
-}
-
 /**
  * Implements hook_form_alter().
  *
@@ -295,28 +270,6 @@ function locale_form_alter(&$form, &$form_state, $form_id) {
  * Implements hook_form_BASE_FORM_ID_alter().
  */
 function locale_form_node_form_alter(&$form, &$form_state) {
-  if (isset($form['#node']->type) && locale_multilingual_node_type($form['#node']->type)) {
-    $languages = language_list(TRUE);
-    foreach ($languages as $langcode => $language) {
-      $language_options[$langcode] = $language->name;
-    }
-    $form['language'] = array(
-      '#type' => 'select',
-      '#title' => t('Language'),
-      '#default_value' => (isset($form['#node']->language) ? $form['#node']->language : ''),
-      '#options' => $language_options,
-      '#empty_value' => LANGUAGE_NONE,
-      '#empty_option' => t('- None -'),
-    );
-  }
-  // Node type without language selector: assign the default for new nodes
-  elseif (!isset($form['#node']->nid)) {
-    $default = language_default();
-    $form['language'] = array(
-      '#type' => 'value',
-      '#value' => $default->langcode
-    );
-  }
   $form['#submit'][] = 'locale_field_node_form_submit';
 }
 
diff --git a/core/modules/locale/locale.test b/core/modules/locale/locale.test
index 2070d1ce672a..d66a54685e0c 100644
--- a/core/modules/locale/locale.test
+++ b/core/modules/locale/locale.test
@@ -1227,7 +1227,7 @@ class LocaleUninstallFunctionalTest extends DrupalWebTestCase {
     $this->assertEqual($GLOBALS['language']->langcode, $this->langcode, t('Current language: %lang', array('%lang' => $GLOBALS['language']->langcode)));
 
     // Enable multilingual workflow option for articles.
-    variable_set('language_content_type_article', 1);
+    variable_set('node_type_language_article', 1);
 
     // Change JavaScript translations directory.
     variable_set('locale_js_directory', 'js_translations');
@@ -1296,10 +1296,6 @@ class LocaleUninstallFunctionalTest extends DrupalWebTestCase {
     $javascript_parsed_count = count(variable_get('javascript_parsed', array()));
     $this->assertEqual($javascript_parsed_count, 0, t('JavaScript parsed count: %count', array('%count' => $javascript_parsed_count)));
 
-    // Check multilingual workflow option for articles.
-    $multilingual = variable_get('language_content_type_article', 0);
-    $this->assertEqual($multilingual, 0, t('Multilingual workflow option: %status', array('%status' => t($multilingual ? 'enabled': 'disabled'))));
-
     // Check JavaScript translations directory.
     $locale_js_directory = variable_get('locale_js_directory', 'languages');
     $this->assertEqual($locale_js_directory, 'languages', t('JavaScript translations directory: %dir', array('%dir' => $locale_js_directory)));
@@ -1946,7 +1942,7 @@ class LocaleContentFunctionalTest extends DrupalWebTestCase {
     $this->drupalGet('admin/structure/types/manage/page');
     $this->assertText(t('Multilingual support'), t('Multilingual support fieldset present on content type configuration form.'));
     $edit = array(
-      'language_content_type' => 1,
+      'node_type_language' => 1,
     );
     $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
     $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), t('Basic page content type has been updated.'));
@@ -2016,7 +2012,7 @@ class LocaleContentFunctionalTest extends DrupalWebTestCase {
     // Set "Article" content type to use multilingual support.
     $this->drupalGet('admin/structure/types/manage/article');
     $edit = array(
-      'language_content_type' => 1,
+      'node_type_language' => 1,
     );
     $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));
     $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Article')), t('Article content type has been updated.'));
@@ -2508,7 +2504,7 @@ class LocaleMultilingualFieldsFunctionalTest extends DrupalWebTestCase {
 
     // Set "Basic page" content type to use multilingual support.
     $edit = array(
-      'language_content_type' => 1,
+      'node_type_language' => 1,
     );
     $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
     $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), t('Basic page content type has been updated.'));
@@ -2622,7 +2618,7 @@ class LocaleCommentLanguageFunctionalTest extends DrupalWebTestCase {
     $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
 
     // Set "Article" content type to use multilingual support.
-    $edit = array('language_content_type' => 1);
+    $edit = array('node_type_language' => 1);
     $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));
 
     // Enable content language negotiation UI.
diff --git a/core/modules/node/content_types.inc b/core/modules/node/content_types.inc
index c76a5e2384d8..e2440d3d08b3 100644
--- a/core/modules/node/content_types.inc
+++ b/core/modules/node/content_types.inc
@@ -187,6 +187,14 @@ function node_type_form($form, &$form_state, $type = NULL) {
     ),
     '#description' => t('Users with the <em>Administer content</em> permission will be able to override these options.'),
   );
+  if (module_exists('language')) {
+    $form['workflow']['node_type_language'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Multilingual support'),
+      '#default_value' => variable_get('node_type_language_' . $type->type, 0),
+      '#description' => t('Add a language selection field to the editing form, allowing you to select from one of the <a href="!languages">enabled languages</a>. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('!languages' => url('admin/config/regional/language'))),
+    );
+  }
   $form['display'] = array(
     '#type' => 'fieldset',
     '#title' => t('Display settings'),
diff --git a/core/modules/node/node.install b/core/modules/node/node.install
index 82fd2e7988ba..b9a5ead007b4 100644
--- a/core/modules/node/node.install
+++ b/core/modules/node/node.install
@@ -456,6 +456,7 @@ function node_uninstall() {
         ->condition('name', 'node_options_' . $type)
         ->condition('name', 'node_submitted_' . $type)
         ->condition('name', 'node_permissions_' . $type)
+        ->condition('name', 'node_type_language_' . $type)
       )
       ->execute();
   }
@@ -524,6 +525,22 @@ function node_update_8000() {
   }
 }
 
+/**
+ * Rename node type language variable names.
+ *
+ * @see http://drupal.org/node/540294
+ */
+function node_update_8001() {
+  $types = db_query('SELECT type FROM {node_type}')->fetchCol();
+  foreach ($types as $type) {
+    $language = variable_get('language_content_type_' . $type);
+    if (isset($language)) {
+      variable_set('node_type_language_' . $type, $language);
+    }
+    variable_del('language_content_type_' . $type);
+  }
+}
+
 /**
  * @} End of "addtogroup updates-7.x-to-8.x"
  * The next series of updates should start at 9000.
diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc
index cd1eb6dfebb1..ab8b5f153290 100644
--- a/core/modules/node/node.pages.inc
+++ b/core/modules/node/node.pages.inc
@@ -181,6 +181,29 @@ function node_form($form, &$form_state, $node) {
   // @todo D8: Remove. Modules should access the node using $form_state['node'].
   $form['#node'] = $node;
 
+  if (variable_get('node_type_language_' . $node->type, 0) && module_exists('language')) {
+    $languages = language_list(TRUE);
+    $language_options = array();
+    foreach ($languages as $langcode => $language) {
+      $language_options[$langcode] = $language->name;
+    }
+    $form['language'] = array(
+      '#type' => 'select',
+      '#title' => t('Language'),
+      '#default_value' => (isset($node->language) ? $node->language : ''),
+      '#options' => $language_options,
+      '#empty_value' => LANGUAGE_NONE,
+    );
+  }
+  else {
+    $form['language'] = array(
+      '#type' => 'value',
+      // New nodes without multilingual support get the default language, old
+      // nodes keep their language if language.module is not available.
+      '#value' => !isset($form['#node']->nid) ? language_default()->langcode : $node->language,
+    );
+  }
+
   $form['additional_settings'] = array(
     '#type' => 'vertical_tabs',
     '#weight' => 99,
diff --git a/core/modules/path/path.test b/core/modules/path/path.test
index cc92b6c9d5e7..ba86b79d54f1 100644
--- a/core/modules/path/path.test
+++ b/core/modules/path/path.test
@@ -260,7 +260,7 @@ class PathLanguageTestCase extends DrupalWebTestCase {
    */
   function testAliasTranslation() {
     // Set 'page' content type to enable translation.
-    variable_set('language_content_type_page', 2);
+    variable_set('node_type_language_page', TRANSLATION_ENABLED);
 
     $english_node = $this->drupalCreateNode(array('type' => 'page'));
     $english_alias = $this->randomName();
diff --git a/core/modules/poll/poll.test b/core/modules/poll/poll.test
index ea8b3410c5ab..0c406f09ed51 100644
--- a/core/modules/poll/poll.test
+++ b/core/modules/poll/poll.test
@@ -843,7 +843,7 @@ class PollTranslateTestCase extends PollTestCase {
     // Set "Poll" content type to use multilingual support with translation.
     $this->drupalGet('admin/structure/types/manage/poll');
     $edit = array();
-    $edit['language_content_type'] = 2;
+    $edit['node_type_language'] = TRANSLATION_ENABLED;
     $this->drupalPost('admin/structure/types/manage/poll', $edit, t('Save content type'));
     $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Poll')), t('Poll content type has been updated.'));
 
diff --git a/core/modules/simpletest/tests/upgrade/drupal-7.language.database.php b/core/modules/simpletest/tests/upgrade/drupal-7.language.database.php
index 02ae24ea79ec..67d51e2ce49a 100644
--- a/core/modules/simpletest/tests/upgrade/drupal-7.language.database.php
+++ b/core/modules/simpletest/tests/upgrade/drupal-7.language.database.php
@@ -510,6 +510,10 @@
   'name' => 'locale_language_providers_weight_language',
   'value' => 'a:5:{s:10:"locale-url";s:2:"-8";s:14:"locale-session";s:2:"-6";s:11:"locale-user";s:2:"-4";s:14:"locale-browser";s:2:"-2";s:16:"language-default";s:2:"10";}',
 ))
+->values(array(
+  'name' => 'language_content_type_article',
+  'value' => 's:1:"1";',
+))
 ->execute();
 
 // Enable the locale module.
diff --git a/core/modules/simpletest/tests/upgrade/upgrade.language.test b/core/modules/simpletest/tests/upgrade/upgrade.language.test
index ed54f5d18fbb..ee77fa77d44a 100644
--- a/core/modules/simpletest/tests/upgrade/upgrade.language.test
+++ b/core/modules/simpletest/tests/upgrade/upgrade.language.test
@@ -40,5 +40,11 @@ class LanguageUpgradePathTestCase extends UpgradePathTestCase {
     foreach ($languages as $language) {
       $this->assertTrue($language->default == ($language->langcode == 'ca'), t('@language default property properly set', array('@language' => $language->name)));
     }
+
+    // Check for node content type settings upgrade.
+    $this->drupalGet('node/add/article');
+    $this->assertFieldByName('language');
+    $this->drupalGet('node/add/page');
+    $this->assertNoFieldByName('language');
   }
 }
diff --git a/core/modules/translation/translation.module b/core/modules/translation/translation.module
index 20f456c9c926..2b2a6ffb623d 100644
--- a/core/modules/translation/translation.module
+++ b/core/modules/translation/translation.module
@@ -111,9 +111,10 @@ function translation_permission() {
  */
 function translation_form_node_type_form_alter(&$form, &$form_state) {
   // Add translation option to content type form.
-  $form['workflow']['language_content_type']['#options'][TRANSLATION_ENABLED] = t('Enabled, with translation');
-  // Description based on text from locale.module.
-  $form['workflow']['language_content_type']['#description'] = t('Enable multilingual support for this content type. If enabled, a language selection field will be added to the editing form, allowing you to select from one of the <a href="!languages">enabled languages</a>. You can also turn on translation for this content type, which lets you have content translated to any of the installed languages. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('!languages' => url('admin/config/regional/language')));
+  $form['workflow']['node_type_language']['#type'] = 'radios';
+  $form['workflow']['node_type_language']['#options'] = array(t('Disabled'), t('Enabled'), TRANSLATION_ENABLED => t('Enabled, with translation'));
+  // Description based on text from node.module.
+  $form['workflow']['node_type_language']['#description'] = t('Add a language selection field to the editing form, allowing you to select from one of the <a href="@languages">enabled languages</a>. You can also turn on translation for this content type, which lets you have content translated to any of the installed languages. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('@languages' => url('admin/config/regional/language')));
 }
 
 /**
@@ -475,7 +476,7 @@ function translation_node_get_translations($tnid) {
  *   Boolean value.
  */
 function translation_supported_type($type) {
-  return variable_get('language_content_type_' . $type, 0) == TRANSLATION_ENABLED;
+  return variable_get('node_type_language_' . $type, 0) == TRANSLATION_ENABLED;
 }
 
 /**
diff --git a/core/modules/translation/translation.test b/core/modules/translation/translation.test
index d7e6d84ca84a..64fede406960 100644
--- a/core/modules/translation/translation.test
+++ b/core/modules/translation/translation.test
@@ -38,7 +38,7 @@ class TranslationTestCase extends DrupalWebTestCase {
     // translation.
     $this->drupalGet('admin/structure/types/manage/page');
     $edit = array();
-    $edit['language_content_type'] = 2;
+    $edit['node_type_language'] = TRANSLATION_ENABLED;
     $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
     $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), t('Basic page content type has been updated.'));
 
@@ -231,7 +231,7 @@ class TranslationTestCase extends DrupalWebTestCase {
     // Disable translation support to check that the language switcher is left
     // untouched only for new nodes.
     $this->drupalLogin($this->admin_user);
-    $edit = array('language_content_type' => 0);
+    $edit = array('node_type_language' => 0);
     $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
     $this->drupalLogin($this->translator);
 
-- 
GitLab