diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 9ad7cfc..2924e42 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1845,7 +1845,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_NONE) && variable_get('node_type_language_' . $node->type, 0)) { + if (($comment_langcode == LANGUAGE_NONE) && !variable_get('node_type_language_locked_' . $node->type, 0)) { $comment_langcode = $language_content->langcode; } $form['langcode'] = array( diff --git a/core/modules/locale/locale.content_types.js b/core/modules/locale/locale.content_types.js new file mode 100644 index 0000000..93f3d9b --- /dev/null +++ b/core/modules/locale/locale.content_types.js @@ -0,0 +1,20 @@ +(function ($) { + +Drupal.behaviors.locale = { + attach: function (context) { + // Provide the vertical tab summaries. + $('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(', '); + }); + } +}; + +})(jQuery); diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 4a786be..0623099 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -267,6 +267,59 @@ function locale_form_alter(&$form, &$form_state, $form_id) { } /** + * Implements hook_form_alter(). + * + * Adds language fields to node type forms. + */ +function locale_form_node_type_form_alter(&$form, &$form_state) { + $type = $form['#node_type']->type; + $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_NONE => 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['additional_settings']['#attached']['js'][] = drupal_get_path('module', 'locale') . '/locale.content_types.js'; + + $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, LANGUAGE_NONE), + ); + $form['language']['node_type_language_locked'] = array( + '#type' => 'checkbox', + '#title' => t('Lock language'), + '#default_value' => variable_get('node_type_language_locked_' . $type, 1), + '#description' => t('Users will not be able to change the default language on content of this type.'), + ); +} + +/** * Implements hook_form_BASE_FORM_ID_alter(). */ function locale_form_node_form_alter(&$form, &$form_state) { diff --git a/core/modules/node/content_types.inc b/core/modules/node/content_types.inc index e2440d3..c76a5e2 100644 --- a/core/modules/node/content_types.inc +++ b/core/modules/node/content_types.inc @@ -187,14 +187,6 @@ 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'))), - ); - } $form['display'] = array( '#type' => 'fieldset', '#title' => t('Display settings'), diff --git a/core/modules/node/node.install b/core/modules/node/node.install index efcce1a..cd49271 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -456,9 +456,12 @@ 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_locked_' . $type) ) ->execute(); + // TODO: node_type_language_translation_enabled_ in the translation module + // ->condition('name', 'node_type_language_translation_enabled_' . $type) } // Delete node search ranking variables. @@ -556,6 +559,31 @@ 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); + if (isset($language)) { + variable_set('node_type_language_default_' . $type, LANGUAGE_NONE); + if ($language) { + variable_set('node_type_language_locked_' . $type, TRUE); + } + else { + variable_set('node_type_language_locked_' . $type, FALSE); + } + if ($language == 2) { + 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 5ee9062..9caa015 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -622,6 +622,42 @@ 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) { + global $user; + + $default_value = variable_get('node_type_language_default_' . $node_type, LANGUAGE_NONE); + + if ($default_value == LANGUAGE_NONE) { + return LANGUAGE_NONE; + } + + switch ($default_value) { + case 'site-default': + $default_value = language_from_default(); + break; + + case 'current': + global $language; + $default_value = $language->langcode; + break; + + case 'user-default': + $default_value = $user->language; + 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 95e2e7d..00a987b 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -87,7 +87,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_NONE); + $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); @@ -181,7 +186,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) { @@ -193,6 +198,7 @@ function node_form($form, &$form_state, $node) { '#default_value' => (isset($node->langcode) ? $node->langcode : ''), '#options' => $language_options, '#empty_value' => LANGUAGE_NONE, + '#disabled' => variable_get('node_type_language_locked_' . $node->type, TRUE), ); } else { diff --git a/core/modules/path/path.test b/core/modules/path/path.test index 3072150..9a63f74 100644 --- a/core/modules/path/path.test +++ b/core/modules/path/path.test @@ -260,7 +260,8 @@ class PathLanguageTestCase extends DrupalWebTestCase { */ function testAliasTranslation() { // Set 'page' content type to enable translation. - variable_set('node_type_language_page', TRANSLATION_ENABLED); + variable_set('node_type_language_locked_page', 0); + variable_set('node_type_language_translation_enabled_page', TRANSLATION_ENABLED); $english_node = $this->drupalCreateNode(array('type' => 'page')); $english_alias = $this->randomName(); diff --git a/core/modules/translation/translation.module b/core/modules/translation/translation.module index e1de320..582116b 100644 --- a/core/modules/translation/translation.module +++ b/core/modules/translation/translation.module @@ -111,10 +111,12 @@ 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_translation_enabled'] = array( + '#type' => 'checkbox', + '#title' => t('Enable translation'), + '#return_value' => TRANSLATION_ENABLED, + '#default_value' => variable_get('node_type_language_translation_enabled_' . $form['#node_type']->type, FALSE), + ); } /** @@ -476,7 +478,7 @@ function translation_node_get_translations($tnid) { * Boolean value. */ function translation_supported_type($type) { - return variable_get('node_type_language_' . $type, 0) == TRANSLATION_ENABLED; + return variable_get('node_type_language_translation_enabled_' . $type, 0) == TRANSLATION_ENABLED; } /** diff --git a/core/modules/translation/translation.test b/core/modules/translation/translation.test index 2a77c03..198a247 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['node_type_language'] = TRANSLATION_ENABLED; + $edit['node_type_language_translation_enabled'] = 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.')); @@ -230,7 +230,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_locked' => TRUE); $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); $this->drupalLogin($this->translator);