diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 1a3580ff4337759ae77c23d116facede10e07a9d..8b124f74f1fe8d1c6192e5baa5d887ac223d6d0d 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1843,7 +1843,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->langcode; - if (($comment_langcode == LANGUAGE_NOT_SPECIFIED) && variable_get('node_type_language_' . $node->type, 0)) { + if (($comment_langcode == LANGUAGE_NOT_SPECIFIED) && !variable_get('node_type_language_selectable_' . $node->type, 0)) { $comment_langcode = $language_content->langcode; } $form['langcode'] = array( diff --git a/core/modules/field/modules/text/text.test b/core/modules/field/modules/text/text.test index 0dbacccf3b2117cc8a4114fd2f5667137062f48c..0b254d92faac471c943d3c7d85c279b55feca007 100644 --- a/core/modules/field/modules/text/text.test +++ b/core/modules/field/modules/text/text.test @@ -438,7 +438,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('node_type_language' => TRANSLATION_ENABLED); + $edit = array('node_type_language_selectable' => 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.test b/core/modules/locale/locale.test index f2395ad90d6fa020b925037a19c1862922e0c923..157d52ee2904b21e64b6cb6472eccfcd434ebfed 100644 --- a/core/modules/locale/locale.test +++ b/core/modules/locale/locale.test @@ -1419,7 +1419,7 @@ class LocaleUninstallFunctionalTest extends DrupalWebTestCase { $this->assertEqual($GLOBALS['language_interface']->langcode, $this->langcode, t('Current language: %lang', array('%lang' => $GLOBALS['language_interface']->langcode))); // Enable multilingual workflow option for articles. - variable_set('node_type_language_article', 1); + variable_set('node_type_language_selectable_article', 1); // Change JavaScript translations directory. variable_set('locale_js_directory', 'js_translations'); @@ -2139,9 +2139,9 @@ class LocaleContentFunctionalTest extends DrupalWebTestCase { // Set "Basic page" content type to use multilingual support. $this->drupalGet('admin/structure/types/manage/page'); - $this->assertText(t('Multilingual support'), t('Multilingual support fieldset present on content type configuration form.')); + $this->assertText(t('Language settings'), t('Multilingual support fieldset present on content type configuration form.')); $edit = array( - 'node_type_language' => 1, + 'node_type_language_selectable' => 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.')); @@ -2211,7 +2211,7 @@ class LocaleContentFunctionalTest extends DrupalWebTestCase { // Set "Article" content type to use multilingual support. $this->drupalGet('admin/structure/types/manage/article'); $edit = array( - 'node_type_language' => 1, + 'node_type_language_selectable' => 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.')); @@ -2707,7 +2707,7 @@ class LocaleMultilingualFieldsFunctionalTest extends DrupalWebTestCase { // Set "Basic page" content type to use multilingual support. $edit = array( - 'node_type_language' => 1, + 'node_type_language_selectable' => 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.')); @@ -2723,7 +2723,7 @@ class LocaleMultilingualFieldsFunctionalTest extends DrupalWebTestCase { */ function testMultilingualNodeForm() { // Create "Basic page" content. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = node_type_get_default_langcode('page'); $title_key = "title"; $title_value = $this->randomName(8); $body_key = "body[$langcode][0][value]"; @@ -2733,7 +2733,6 @@ class LocaleMultilingualFieldsFunctionalTest extends DrupalWebTestCase { $edit = array(); $edit[$title_key] = $title_value; $edit[$body_key] = $body_value; - $edit['langcode'] = 'en'; $this->drupalPost('node/add/page', $edit, t('Save')); // Check that the node exists in the database. @@ -2772,7 +2771,7 @@ class LocaleMultilingualFieldsFunctionalTest extends DrupalWebTestCase { */ function testMultilingualDisplaySettings() { // Create "Basic page" content. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = node_type_get_default_langcode('page'); $title_key = "title"; $title_value = $this->randomName(8); $body_key = "body[$langcode][0][value]"; @@ -2782,7 +2781,6 @@ class LocaleMultilingualFieldsFunctionalTest extends DrupalWebTestCase { $edit = array(); $edit[$title_key] = $title_value; $edit[$body_key] = $body_value; - $edit['langcode'] = 'en'; $this->drupalPost('node/add/page', $edit, t('Save')); // Check that the node exists in the database. @@ -2825,7 +2823,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('node_type_language' => 1); + $edit = array('node_type_language_selectable' => 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 2e45c9a7c7549ebabc7a2dd9658a89755a2e2b0d..7bba641d2fe9044a37101332d1349d4f6f2edb50 100644 --- a/core/modules/node/content_types.inc +++ b/core/modules/node/content_types.inc @@ -186,11 +186,48 @@ function node_type_form($form, &$form_state, $type = NULL) { '#description' => t('Users with the Administer content 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 enabled 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'))), + $languages = language_list(); + $grouped_languages = array(); + foreach ($languages as $langcode => $language) { + $grouped_languages[(int) $language->enabled][$langcode] = $language; + } + $groups = array(t('Disabled'), t('Enabled')); + $defaults = array( + LANGUAGE_NOT_SPECIFIED => t('- None -'), + 'site_default' => t("Site's default"), + 'current' => t('Current language'), + 'user_default' => t("User's default"), + ); + $lang_options = array('Special options' => $defaults); + foreach (array(1, 0) as $status) { + if (isset($grouped_languages[$status])) { + $group = $groups[$status]; + foreach ($grouped_languages[$status] as $langcode => $language) { + $lang_options[$group][$langcode] = $language->name; + } + } + } + $form['language'] = array( + '#type' => 'fieldset', + '#title' => t('Language settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#group' => 'additional_settings', + ); + $form['language']['node_type_language_default'] = array( + '#type' => 'select', + '#title' => t('Default language'), + '#options' => $lang_options, + '#default_value' => variable_get('node_type_language_default_' . $type->type, 'site_default'), + ); + $form['language']['node_type_language_selectable'] = array( + '#type' => 'radios', + '#title' => t('Language selection on node edit form'), + '#options' => array( + 0 => t('Locked'), + 1 => t('Selectable'), + ), + '#default_value' => variable_get('node_type_language_selectable_' . $type->type, 0), ); } $form['display'] = array( diff --git a/core/modules/node/content_types.js b/core/modules/node/content_types.js index 0031c323fac33019341d5aab9757ecf2702b2e8f..a3ec87de0d80f4ddbaff3aa24d5f660ca100bab9 100644 --- a/core/modules/node/content_types.js +++ b/core/modules/node/content_types.js @@ -18,6 +18,17 @@ Drupal.behaviors.contentTypes = { } return vals.join(', '); }); + $('fieldset#edit-language', context).drupalSetSummary(function(context) { + var vals = []; + + vals.push($(".form-item-node-type-language-default select option:selected", context).text()); + + $('input:checked', context).next('label').each(function() { + vals.push(Drupal.checkPlain($(this).text())); + }); + + return vals.join(', '); + }); $('fieldset#edit-display', context).drupalSetSummary(function(context) { var vals = []; $('input:checked', context).next('label').each(function() { diff --git a/core/modules/node/node.install b/core/modules/node/node.install index b2616ab6b87b6121acaacb402136db8983f652bb..0f9c274bcb5368a36a1c6ec6e291a859d1248f0d 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -458,7 +458,8 @@ function node_uninstall() { ->condition('name', 'node_options_' . $type) ->condition('name', 'node_submitted_' . $type) ->condition('name', 'node_permissions_' . $type) - ->condition('name', 'node_type_language_' . $type) + ->condition('name', 'node_type_language_default_' . $type) + ->condition('name', 'node_type_language_selectable_' . $type) ) ->execute(); } @@ -558,6 +559,23 @@ function node_update_8002() { } /** + * Rename node type language variable names. + * + * @see http://drupal.org/node/258785 + */ +function node_update_8003() { + $types = db_query('SELECT type FROM {node_type}')->fetchCol(); + foreach ($types as $type) { + $language = variable_get('node_type_language_' . $type, 0); + if (isset($language)) { + variable_set('node_type_language_default_' . $type, language_default()->langcode); + variable_set('node_type_language_selectable_' . $type, $language); + } + variable_del('node_type_language_' . $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.module b/core/modules/node/node.module index be60e48920c902ef1b1914330226b466a37f5c2a..4c4748579399c1ac2205414e4ba191f790b0bf9b 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -634,6 +634,47 @@ function node_field_extra_fields() { } /** + * Get the default language for a node type + * + * @param string $node_type + * The type of node + * + * @return (string) + * The language code of the node type's default langcode + */ +function node_type_get_default_langcode($node_type) { + $default_value = variable_get('node_type_language_default_' . $node_type, 'site_default'); + + if ($default_value == LANGUAGE_NOT_SPECIFIED) { + return LANGUAGE_NOT_SPECIFIED; + } + + switch ($default_value) { + case 'site_default': + $default_value = language_default()->langcode; + break; + + case 'current': + global $language_interface; + $default_value = $language_interface->langcode; + break; + + case 'user_default': + global $user; + if (!empty($user->preferred_langcode)) { + $default_value = $user->preferred_langcode; + } + else { + global $language_interface; + $default_value = $language_interface->langcode; + } + break; + } + + return $default_value; +} + +/** * Deletes a node type from the database. * * @param $type diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index 4e94b2613de36dff259775335e08680b2527dc3c..85541411c1f941d6ebd4feec3f2fa1e8b64b80b7 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -81,7 +81,12 @@ function node_add($type) { global $user; $types = node_type_get_types(); - $node = (object) array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'langcode' => LANGUAGE_NOT_SPECIFIED); + $node = (object) array( + 'uid' => $user->uid, + 'name' => (isset($user->name) ? $user->name : ''), + 'type' => $type, + 'langcode' => node_type_get_default_langcode($type) + ); drupal_set_title(t('Create @name', array('@name' => $types[$type]->name)), PASS_THROUGH); $output = drupal_get_form($type . '_node_form', $node); @@ -175,7 +180,7 @@ 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')) { + if (module_exists('language')) { $languages = language_list(TRUE); $language_options = array(); foreach ($languages as $langcode => $language) { @@ -187,14 +192,16 @@ function node_form($form, &$form_state, $node) { '#default_value' => (isset($node->langcode) ? $node->langcode : ''), '#options' => $language_options, '#empty_value' => LANGUAGE_NOT_SPECIFIED, + '#disabled' => !variable_get('node_type_language_selectable_' . $node->type, 0), ); } else { $form['langcode'] = 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->langcode, + // New nodes without multilingual support get the default language of the + // content type (for new nodes already set in node_add), old nodes keep + // their language if language.module is not available. + '#value' => $node->langcode, ); } diff --git a/core/modules/path/path.test b/core/modules/path/path.test index 32220ee469b992fbdc01e2ad07ee1d135f80dd43..7e968f7f48ddd90f4f0861a4e90c3edcb9cb74fd 100644 --- a/core/modules/path/path.test +++ b/core/modules/path/path.test @@ -302,7 +302,7 @@ class PathLanguageTestCase extends PathTestCase { */ function testAliasTranslation() { // Set 'page' content type to enable translation. - variable_set('node_type_language_page', TRANSLATION_ENABLED); + variable_set('node_type_language_selectable_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 ace8d56ca6f6f0efe75bc91b71e9bcaeedb88ff0..880057e0dbf46e20ccf64dd2a70b4a66c487cf69 100644 --- a/core/modules/poll/poll.test +++ b/core/modules/poll/poll.test @@ -833,8 +833,7 @@ class PollTranslateTestCase extends PollWebTestCase { // Set "Poll" content type to use multilingual support with translation. $this->drupalGet('admin/structure/types/manage/poll'); - $edit = array(); - $edit['node_type_language'] = TRANSLATION_ENABLED; + $edit = array('node_type_language_selectable' => 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/upgrade.language.test b/core/modules/simpletest/tests/upgrade/upgrade.language.test index 192f00c3248532469400e88a05787cc74dd6b61b..d84bfed50f4669fec134df0bb89cd13b956ef496 100644 --- a/core/modules/simpletest/tests/upgrade/upgrade.language.test +++ b/core/modules/simpletest/tests/upgrade/upgrade.language.test @@ -77,7 +77,7 @@ class LanguageUpgradePathTestCase extends UpgradePathTestCase { $this->drupalGet('node/add/article'); $this->assertFieldByName('langcode'); $this->drupalGet('node/add/page'); - $this->assertNoFieldByName('langcode'); + $this->assertFieldByName('langcode'); // Check that the user language value was retained in both langcode and // preferred_langcode. diff --git a/core/modules/translation/translation.install b/core/modules/translation/translation.install new file mode 100644 index 0000000000000000000000000000000000000000..02046993f32eab23123eaea167d8ae796297d53a --- /dev/null +++ b/core/modules/translation/translation.install @@ -0,0 +1,21 @@ +fetchCol(); + foreach ($types as $type) { + $translatable = variable_get('node_type_language_selectable_' . $type, 0); + if ($translatable == TRANSLATION_ENABLED) { + variable_set('node_type_language_selectable_' . $type, 1); + } + } +} diff --git a/core/modules/translation/translation.module b/core/modules/translation/translation.module index ef34ea60372a2036909c06c488b61192076db82a..e72832fe055de2b4997aa45d303dc76534124454 100644 --- a/core/modules/translation/translation.module +++ b/core/modules/translation/translation.module @@ -118,10 +118,7 @@ function translation_permission() { */ function translation_form_node_type_form_alter(&$form, &$form_state) { // Add translation option to content type form. - $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 enabled languages. 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['language']['node_type_language_selectable']['#options'][TRANSLATION_ENABLED] = t('Selectable with translation support'); } /** @@ -488,7 +485,7 @@ function translation_node_get_translations($tnid) { * TRUE if translation is supported, and FALSE if not. */ function translation_supported_type($type) { - return variable_get('node_type_language_' . $type, 0) == TRANSLATION_ENABLED; + return variable_get('node_type_language_selectable_' . $type, 0) == TRANSLATION_ENABLED; } /** diff --git a/core/modules/translation/translation.test b/core/modules/translation/translation.test index e2b83584f63bf923fcccbf118a1e38ee06307b1e..9a6e77945e4c96f1199388e412bad8bbb25b99d3 100644 --- a/core/modules/translation/translation.test +++ b/core/modules/translation/translation.test @@ -42,8 +42,7 @@ class TranslationTestCase extends DrupalWebTestCase { // Set "Basic page" content type to use multilingual support with // translation. $this->drupalGet('admin/structure/types/manage/page'); - $edit = array(); - $edit['node_type_language'] = TRANSLATION_ENABLED; + $edit = array('node_type_language_selectable' => 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.')); @@ -234,7 +233,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('node_type_language' => 0); + $edit = array('node_type_language_selectable' => 0); $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); $this->drupalLogin($this->translator);