diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 7c96247..ffa98a5 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1837,12 +1837,13 @@ function comment_form($form, &$form_state, Comment $comment) { } $form['node_type'] = array('#type' => 'value', '#value' => 'comment_node_' . $node->type); - // If a content type has multilingual support we set the comment to inherit the - // content language. Otherwise mark the comment as language neutral. + // Make the comment inherit the node language unless specifically set. $comment_langcode = $comment->langcode; - if (($comment_langcode == LANGUAGE_NOT_SPECIFIED) && variable_get('node_type_language_' . $node->type, 0)) { + if ($comment_langcode == LANGUAGE_NOT_SPECIFIED) { $comment_langcode = $language_content->langcode; } + + // Uses the language of the content as comment language. $form['langcode'] = array( '#type' => 'value', '#value' => $comment_langcode, diff --git a/core/modules/field/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php b/core/modules/field/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php index 2432d15..0d3739f 100644 --- a/core/modules/field/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php +++ b/core/modules/field/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php @@ -43,7 +43,7 @@ class TextTranslationTest extends WebTestBase { $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_hidden' => FALSE, 'node_type_language_translation_enabled' => TRUE); $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/lib/Drupal/locale/Tests/LocaleCommentLanguageTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleCommentLanguageTest.php index 16fc83f..9bb8bc0 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleCommentLanguageTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleCommentLanguageTest.php @@ -38,7 +38,7 @@ class LocaleCommentLanguageTest extends WebTestBase { $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_hidden' => FALSE); $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type')); // Enable content language negotiation UI. diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleContentTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleContentTest.php index 0c5cea3..fbedc33 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleContentTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleContentTest.php @@ -82,9 +82,9 @@ class LocaleContentTest extends WebTestBase { // 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_hidden' => FALSE, ); $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.')); @@ -152,7 +152,7 @@ class LocaleContentTest extends WebTestBase { // Set "Article" content type to use multilingual support. $this->drupalGet('admin/structure/types/manage/article'); $edit = array( - 'node_type_language' => 1, + 'node_type_language_hidden' => FALSE, ); $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/lib/Drupal/locale/Tests/LocaleMultilingualFieldsTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleMultilingualFieldsTest.php index 2a8299a..92af494 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleMultilingualFieldsTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleMultilingualFieldsTest.php @@ -44,7 +44,7 @@ class LocaleMultilingualFieldsTest extends WebTestBase { // Set "Basic page" content type to use multilingual support. $edit = array( - 'node_type_language' => 1, + 'node_type_language_hidden' => FALSE, ); $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.')); @@ -60,7 +60,7 @@ class LocaleMultilingualFieldsTest extends WebTestBase { */ 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]"; @@ -70,7 +70,6 @@ class LocaleMultilingualFieldsTest extends WebTestBase { $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. @@ -109,7 +108,7 @@ class LocaleMultilingualFieldsTest extends WebTestBase { */ 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]"; @@ -119,7 +118,6 @@ class LocaleMultilingualFieldsTest extends WebTestBase { $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. diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php index 71aff68..30595dd 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php @@ -52,11 +52,9 @@ class LocaleUninstallTest extends WebTestBase { $this->assertEqual(drupal_container()->get(LANGUAGE_TYPE_INTERFACE)->langcode, $this->langcode, t('Current language: %lang', array('%lang' => drupal_container()->get(LANGUAGE_TYPE_INTERFACE)->langcode))); // Enable multilingual workflow option for articles. - variable_set('node_type_language_article', 1); - + variable_set('node_type_language_hidden_article',FALSE); // Change JavaScript translations directory. variable_set('locale_js_directory', 'js_translations'); - // Build the JavaScript translation file for French. $user = $this->drupalCreateUser(array('translate interface', 'access administration pages')); $this->drupalLogin($user); diff --git a/core/modules/node/content_types.inc b/core/modules/node/content_types.inc index 6bb7969..3ebc6dc 100644 --- a/core/modules/node/content_types.inc +++ b/core/modules/node/content_types.inc @@ -185,11 +185,39 @@ 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( + $languages = language_list(); + // @todo use language_special_languages() if #1471432 is comitted. + $lang_options = array( + LANGUAGE_NOT_SPECIFIED => t('Not specified'), + LANGUAGE_NOT_APPLICABLE => t('Not applicable'), + LANGUAGE_MULTIPLE => t('Multiple languages'), + 'site_default' => t("Site's default language"), + 'current_interface' => t('Current interface language'), + 'authors_default' => t("Author's preferred language"), + ); + + foreach ($languages as $langcode => $language) { + $lang_options[$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'), + '#description' => t('Explanation of the language options is found on the languages list page.', array('@languages_list_page' => url('admin/config/regional/language'))), + ); + $form['language']['node_type_language_hidden'] = 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'))), + '#title' => t('Hide language selector'), + '#default_value' => variable_get('node_type_language_hidden_' . $type->type, TRUE), ); } $form['display'] = array( diff --git a/core/modules/node/content_types.js b/core/modules/node/content_types.js index 5c1c44e..87fc460 100644 --- a/core/modules/node/content_types.js +++ b/core/modules/node/content_types.js @@ -21,6 +21,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(', '); + }); $context.find('fieldset#edit-display').drupalSetSummary(function(context) { var vals = []; var $context = $(context); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php new file mode 100644 index 0000000..39db014 --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php @@ -0,0 +1,70 @@ + 'Node type initial language', + 'description' => 'Tests node type initial language settings.', + 'group' => 'Node', + ); + } + + function setUp() { + parent::setUp(array('language')); + $web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer languages')); + $this->drupalLogin($web_user); + } + + /** + * Tests the node type initial language defaults, and modify them. + * + * The default initial language must be the site's default, and the language + * locked option must be on. + */ + function testNodeTypeInitialLanguageDefaults() { + $this->drupalGet('admin/structure/types/manage/article'); + $this->assertOptionSelected('edit-node-type-language-default', 'site_default', 'The default inital language is the site default.'); + $this->assertFieldChecked('edit-node-type-language-hidden', 'Language selector is hidden by default.'); + + $this->drupalGet('node/add/article'); + $this->assertNoField('langcode', 'Language is not selectable on node add/edit page by default.'); + + // Adds a new language and set it as default. + $edit = array( + 'predefined_langcode' => 'hu', + ); + $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); + $edit = array( + 'site_default' => 'hu', + ); + $this->drupalPost('admin/config/regional/language', $edit, t('Save configuration')); + + // Tests the initial language after changing the site default language. + // First unhide the language selector + $edit = array( + 'node_type_language_hidden' => FALSE, + ); + $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type')); + $this->drupalGet('node/add/article'); + $this->assertField('langcode', 'Language is selectable on node add/edit page when language not hidden.'); + $this->assertOptionSelected('edit-langcode', 'hu', 'The inital language is the site default on the node add page after the site default language is changed.'); + + // Changes the inital language settings. + $edit = array( + 'node_type_language_default' => 'en', + ); + $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type')); + $this->drupalGet('node/add/article'); + $this->assertOptionSelected('edit-langcode', 'en', 'The inital language is the defined language.'); + } +} diff --git a/core/modules/node/node.install b/core/modules/node/node.install index 6f806e9..7382320 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -458,7 +458,9 @@ 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_hidden_' . $type) + ->condition('name', 'node_type_language_translation_enabled_' . $type) ) ->execute(); } @@ -520,9 +522,9 @@ function _update_7000_node_get_types() { 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); + $node_type_language = variable_get('language_content_type_' . $type); + if (isset($node_type_language)) { + variable_set('node_type_language_' . $type, $node_type_language); } variable_del('language_content_type_' . $type); } @@ -543,6 +545,29 @@ function node_update_8002() { } /** - * @} End of "addtogroup updates-7.x-to-8.x". + * Rename node type language variable names. + */ +function node_update_8003() { + $types = db_query('SELECT type FROM {node_type}')->fetchCol(); + foreach ($types as $type) { + variable_set('node_type_language_default_' . $type, LANGUAGE_NOT_SPECIFIED); + $node_type_language = variable_get('node_type_language_' . $type, 0); + if ($node_type_language == 0) { + variable_set('node_type_language_hidden_' . $type, TRUE); + } + if ($node_type_language == 2) { + // Translation was enabled, so enable it again and + // unhide the language selector. Because if language is + // LANGUAGE_NOT_SPECIFIED and the selector hidden, translation + // cannot be enabled. + variable_set('node_type_language_hidden_' . $type, FALSE); + variable_set('node_type_language_translation_enabled_' . $type, TRUE); + } + 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 e787c7d..17e0599 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -629,6 +629,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'); + + $language_interface = drupal_container()->get(LANGUAGE_TYPE_INTERFACE); + + if ($default_value == LANGUAGE_NOT_SPECIFIED) { + return LANGUAGE_NOT_SPECIFIED; + } + + switch ($default_value) { + case 'site_default': + $default_value = language_default()->langcode; + break; + + case 'current_interface': + $default_value = $language_interface->langcode; + break; + + case 'authors_default': + global $user; + if (!empty($user->preferred_langcode)) { + $default_value = $user->preferred_langcode; + } + else { + $default_value = $language_interface->langcode; + } + break; + } + + return $default_value; +} + +/** * Deletes a node type from the database. * * @param $name diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index 70383b7..a4da515 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -91,7 +91,7 @@ function node_add($type) { 'uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, - 'langcode' => LANGUAGE_NOT_SPECIFIED, + '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); @@ -186,7 +186,7 @@ function node_form($form, &$form_state, Node $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(); $language_options = array(); foreach ($languages as $langcode => $language) { @@ -195,17 +195,18 @@ function node_form($form, &$form_state, Node $node) { $form['langcode'] = array( '#type' => 'select', '#title' => t('Language'), - '#default_value' => (isset($node->langcode) ? $node->langcode : ''), + '#default_value' => $node->langcode, '#options' => $language_options, '#empty_value' => LANGUAGE_NOT_SPECIFIED, ); + if (variable_get('node_type_language_hidden_' . $node->type, TRUE)) { + $form['langcode']['#access'] = FALSE; + } } 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, + '#value' => $node->langcode, ); } diff --git a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php index 096729f..b3dba0e 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php @@ -42,7 +42,8 @@ class PathLanguageTest extends PathTestBase { */ function testAliasTranslation() { // Set 'page' content type to enable translation. - variable_set('node_type_language_page', TRANSLATION_ENABLED); + variable_set('node_type_language_hidden_page', FALSE); + variable_set('node_type_language_translation_enabled_page', TRUE); $english_node = $this->drupalCreateNode(array('type' => 'page')); $english_alias = $this->randomName(); diff --git a/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php b/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php index 6b89cad..ee1d4d7 100644 --- a/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php +++ b/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php @@ -50,8 +50,7 @@ class PollTranslateTest extends PollTestBase { // 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_hidden' => FALSE, 'node_type_language_translation_enabled' => TRUE); $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/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php index 81e9676..9dfe0f4 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php @@ -75,12 +75,11 @@ class LanguageUpgradePathTest extends UpgradePathTestBase { $this->assertRaw('Chuvash', 'There is a Chuvash translation of the node.'); $this->assertLinkByHref("node/$translation_nid", 0, 'The translation table links to the Chuvash translation.'); $this->assertRaw('Catalann/aNot translated', 'There is no Catalan translation of this node.'); - // Check for node content type settings upgrade. $this->drupalGet('node/add/article'); - $this->assertFieldByName('langcode'); + $this->assertField('langcode', 'There is a language selector.'); $this->drupalGet('node/add/page'); - $this->assertNoFieldByName('langcode'); + $this->assertNoField('langcode', 'There is no language selector.'); // Check that the user language value was retained in both langcode and // preferred_langcode. diff --git a/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php b/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php index b8dcc3d..2c2a4d2 100644 --- a/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php +++ b/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php @@ -42,8 +42,7 @@ class TranslationTest extends WebTestBase { // 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_hidden' => FALSE, 'node_type_language_translation_enabled' => TRUE); $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.')); @@ -222,7 +221,7 @@ class TranslationTest extends WebTestBase { // 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_hidden' => TRUE, 'node_type_language_translation_enabled' => FALSE); $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); $this->drupalLogin($this->translator); diff --git a/core/modules/translation/translation.js b/core/modules/translation/translation.js index d4b9f53..7bc1c21 100644 --- a/core/modules/translation/translation.js +++ b/core/modules/translation/translation.js @@ -4,10 +4,10 @@ Drupal.behaviors.TranslationEnable = { attach: function (context) { - $('#edit-node-type-language-default, #edit-node-type-language-locked', context).change(function(context) { + $('#edit-node-type-language-default, #edit-node-type-language-hidden', context).change(function(context) { var default_language = $('#edit-node-type-language-default').val(); - if ((default_language == 'und' || default_language == 'zxx' || default_language == 'mul') && $('#edit-node-type-language-locked').attr('checked')) { + if ((default_language == 'und' || default_language == 'zxx' || default_language == 'mul') && $('#edit-node-type-language-hidden').attr('checked')) { $('.form-item-node-type-language-translation-enabled').hide(); $('#edit-node-type-language-translation-enabled').removeAttr('checked'); } else { diff --git a/core/modules/translation/translation.module b/core/modules/translation/translation.module index b2c0635..b994b88 100644 --- a/core/modules/translation/translation.module +++ b/core/modules/translation/translation.module @@ -22,11 +22,6 @@ use Drupal\node\Node; /** - * Identifies a content type which has translation support enabled. - */ -const TRANSLATION_ENABLED = 2; - -/** * Implements hook_help(). */ function translation_help($path, $arg) { @@ -119,11 +114,34 @@ function translation_permission() { * Implements hook_form_FORM_ID_alter() for node_type_form(). */ function translation_form_node_type_form_alter(&$form, &$form_state) { + // Hide form element if default language is a constant. + // TODO: When form #states allows OR values change this to use form #states. + $form['#attached']['js'] = array( + drupal_get_path('module', 'translation') . '/translation.js', + ); // 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_translation_enabled'] = array( + '#type' => 'checkbox', + '#title' => t('Enable translation'), + '#default_value' => variable_get('node_type_language_translation_enabled_' . $form['#node_type']->type, FALSE), + '#element_validate' => array('translation_node_type_language_translation_enabled_validate'), + '#prefix' => "", + ); +} + +/** + * Checks if translation can be enabled. + * + * If language is set to one of the special languages + * and language selector is not hidden, translation cannot be enabled. + */ +function translation_node_type_language_translation_enabled_validate($element, &$form_state, $form) { + // @todo Change this to language_is_locked() when #1471432 is comitted. + $locked_language = in_array($form_state['values']['node_type_language_default'], array(LANGUAGE_NOT_SPECIFIED, LANGUAGE_NOT_APPLICABLE, LANGUAGE_MULTIPLE)); + if ($locked_language && $form_state['values']['node_type_language_hidden'] && $form_state['values']['node_type_language_translation_enabled']) { + // @todo use language_special_languages() if #1471432 is comitted. + form_set_error('node_type_language_translation_enabled', t('Translation is not supported if language is always one of: Not specified, Not applicable or Multiple languages')); + } } /** @@ -144,9 +162,9 @@ function translation_form_node_form_alter(&$form, &$form_state) { $form['langcode']['#disabled'] = TRUE; } elseif (!empty($node->nid) && !empty($node->tnid)) { - // Disable languages for existing translations, so it is not possible to switch this - // node to some language which is already in the translation set. Also remove the - // language neutral option. + // Disable languages for existing translations, so it is not possible + // to switch this node to some language which is already in the + // translation set. Also remove the language neutral option. unset($form['langcode']['#options'][LANGUAGE_NOT_SPECIFIED]); foreach (translation_node_get_translations($node->tnid) as $langcode => $translation) { if ($translation->nid != $node->nid) { @@ -165,7 +183,7 @@ function translation_form_node_form_alter(&$form, &$form_state) { '#weight' => 30, ); if ($node->tnid == $node->nid) { - // This is the source node of the translation + // This is the source node of the translation. $form['translation']['retranslate'] = array( '#type' => 'checkbox', '#title' => t('Flag translations as outdated'), @@ -367,7 +385,7 @@ function translation_node_validate(Node $node, $form) { if (translation_supported_type($node->type) && (!empty($node->tnid) || !empty($form['#node']->translation_source->nid))) { $tnid = !empty($node->tnid) ? $node->tnid : $form['#node']->translation_source->nid; $translations = translation_node_get_translations($tnid); - if (isset($translations[$node->langcode]) && $translations[$node->langcode]->nid != $node->nid ) { + if (isset($translations[$node->langcode]) && $translations[$node->langcode]->nid != $node->nid) { form_set_error('langcode', t('There is already a translation in this language.')); } } @@ -461,7 +479,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_translation_enabled_' . $type, FALSE); } /**