Commit 6e431c53 authored by Dries's avatar Dries
Browse files

- Patch #540294 by Gábor Hojtsy, clemens.tolboom, Xano: node language settings...

- Patch #540294 by Gábor Hojtsy, clemens.tolboom, Xano: node language settings from Locale to Node module.
parent ddf4b81f
...@@ -1841,7 +1841,7 @@ function comment_form($form, &$form_state, $comment) { ...@@ -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 // If a content type has multilingual support we set the comment to inherit the
// content language. Otherwise mark the comment as language neutral. // content language. Otherwise mark the comment as language neutral.
$comment_langcode = $comment->language; $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; $comment_langcode = $language_content->langcode;
} }
$form['language'] = array( $form['language'] = array(
......
...@@ -434,7 +434,7 @@ class TextTranslationTestCase extends DrupalWebTestCase { ...@@ -434,7 +434,7 @@ class TextTranslationTestCase extends DrupalWebTestCase {
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
// Set "Article" content type to use multilingual support with translation. // 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->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.')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Article')), t('Article content type has been updated.'));
} }
......
...@@ -246,31 +246,6 @@ function locale_language_selector_form($user) { ...@@ -246,31 +246,6 @@ function locale_language_selector_form($user) {
return $form; 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(). * Implements hook_form_alter().
* *
...@@ -295,28 +270,6 @@ function locale_form_alter(&$form, &$form_state, $form_id) { ...@@ -295,28 +270,6 @@ function locale_form_alter(&$form, &$form_state, $form_id) {
* Implements hook_form_BASE_FORM_ID_alter(). * Implements hook_form_BASE_FORM_ID_alter().
*/ */
function locale_form_node_form_alter(&$form, &$form_state) { 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'; $form['#submit'][] = 'locale_field_node_form_submit';
} }
......
...@@ -1227,7 +1227,7 @@ class LocaleUninstallFunctionalTest extends DrupalWebTestCase { ...@@ -1227,7 +1227,7 @@ class LocaleUninstallFunctionalTest extends DrupalWebTestCase {
$this->assertEqual($GLOBALS['language']->langcode, $this->langcode, t('Current language: %lang', array('%lang' => $GLOBALS['language']->langcode))); $this->assertEqual($GLOBALS['language']->langcode, $this->langcode, t('Current language: %lang', array('%lang' => $GLOBALS['language']->langcode)));
// Enable multilingual workflow option for articles. // Enable multilingual workflow option for articles.
variable_set('language_content_type_article', 1); variable_set('node_type_language_article', 1);
// Change JavaScript translations directory. // Change JavaScript translations directory.
variable_set('locale_js_directory', 'js_translations'); variable_set('locale_js_directory', 'js_translations');
...@@ -1296,10 +1296,6 @@ class LocaleUninstallFunctionalTest extends DrupalWebTestCase { ...@@ -1296,10 +1296,6 @@ class LocaleUninstallFunctionalTest extends DrupalWebTestCase {
$javascript_parsed_count = count(variable_get('javascript_parsed', array())); $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))); $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. // Check JavaScript translations directory.
$locale_js_directory = variable_get('locale_js_directory', 'languages'); $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))); $this->assertEqual($locale_js_directory, 'languages', t('JavaScript translations directory: %dir', array('%dir' => $locale_js_directory)));
...@@ -1946,7 +1942,7 @@ class LocaleContentFunctionalTest extends DrupalWebTestCase { ...@@ -1946,7 +1942,7 @@ class LocaleContentFunctionalTest extends DrupalWebTestCase {
$this->drupalGet('admin/structure/types/manage/page'); $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('Multilingual support'), t('Multilingual support fieldset present on content type configuration form.'));
$edit = array( $edit = array(
'language_content_type' => 1, 'node_type_language' => 1,
); );
$this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); $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.')); $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 { ...@@ -2016,7 +2012,7 @@ class LocaleContentFunctionalTest extends DrupalWebTestCase {
// Set "Article" content type to use multilingual support. // Set "Article" content type to use multilingual support.
$this->drupalGet('admin/structure/types/manage/article'); $this->drupalGet('admin/structure/types/manage/article');
$edit = array( $edit = array(
'language_content_type' => 1, 'node_type_language' => 1,
); );
$this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type')); $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.')); $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 { ...@@ -2508,7 +2504,7 @@ class LocaleMultilingualFieldsFunctionalTest extends DrupalWebTestCase {
// Set "Basic page" content type to use multilingual support. // Set "Basic page" content type to use multilingual support.
$edit = array( $edit = array(
'language_content_type' => 1, 'node_type_language' => 1,
); );
$this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); $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.')); $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 { ...@@ -2622,7 +2618,7 @@ class LocaleCommentLanguageFunctionalTest extends DrupalWebTestCase {
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
// Set "Article" content type to use multilingual support. // 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')); $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));
// Enable content language negotiation UI. // Enable content language negotiation UI.
......
...@@ -187,6 +187,14 @@ function node_type_form($form, &$form_state, $type = NULL) { ...@@ -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.'), '#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( $form['display'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Display settings'), '#title' => t('Display settings'),
......
...@@ -456,6 +456,7 @@ function node_uninstall() { ...@@ -456,6 +456,7 @@ function node_uninstall() {
->condition('name', 'node_options_' . $type) ->condition('name', 'node_options_' . $type)
->condition('name', 'node_submitted_' . $type) ->condition('name', 'node_submitted_' . $type)
->condition('name', 'node_permissions_' . $type) ->condition('name', 'node_permissions_' . $type)
->condition('name', 'node_type_language_' . $type)
) )
->execute(); ->execute();
} }
...@@ -524,6 +525,22 @@ function node_update_8000() { ...@@ -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" * @} End of "addtogroup updates-7.x-to-8.x"
* The next series of updates should start at 9000. * The next series of updates should start at 9000.
......
...@@ -181,6 +181,29 @@ function node_form($form, &$form_state, $node) { ...@@ -181,6 +181,29 @@ function node_form($form, &$form_state, $node) {
// @todo D8: Remove. Modules should access the node using $form_state['node']. // @todo D8: Remove. Modules should access the node using $form_state['node'].
$form['#node'] = $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( $form['additional_settings'] = array(
'#type' => 'vertical_tabs', '#type' => 'vertical_tabs',
'#weight' => 99, '#weight' => 99,
......
...@@ -260,7 +260,7 @@ class PathLanguageTestCase extends DrupalWebTestCase { ...@@ -260,7 +260,7 @@ class PathLanguageTestCase extends DrupalWebTestCase {
*/ */
function testAliasTranslation() { function testAliasTranslation() {
// Set 'page' content type to enable translation. // 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_node = $this->drupalCreateNode(array('type' => 'page'));
$english_alias = $this->randomName(); $english_alias = $this->randomName();
......
...@@ -843,7 +843,7 @@ class PollTranslateTestCase extends PollTestCase { ...@@ -843,7 +843,7 @@ class PollTranslateTestCase extends PollTestCase {
// Set "Poll" content type to use multilingual support with translation. // Set "Poll" content type to use multilingual support with translation.
$this->drupalGet('admin/structure/types/manage/poll'); $this->drupalGet('admin/structure/types/manage/poll');
$edit = array(); $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->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.')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Poll')), t('Poll content type has been updated.'));
......
...@@ -510,6 +510,10 @@ ...@@ -510,6 +510,10 @@
'name' => 'locale_language_providers_weight_language', '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";}', '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(); ->execute();
// Enable the locale module. // Enable the locale module.
......
...@@ -40,5 +40,11 @@ class LanguageUpgradePathTestCase extends UpgradePathTestCase { ...@@ -40,5 +40,11 @@ class LanguageUpgradePathTestCase extends UpgradePathTestCase {
foreach ($languages as $language) { foreach ($languages as $language) {
$this->assertTrue($language->default == ($language->langcode == 'ca'), t('@language default property properly set', array('@language' => $language->name))); $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');
} }
} }
...@@ -111,9 +111,10 @@ function translation_permission() { ...@@ -111,9 +111,10 @@ function translation_permission() {
*/ */
function translation_form_node_type_form_alter(&$form, &$form_state) { function translation_form_node_type_form_alter(&$form, &$form_state) {
// Add translation option to content type form. // Add translation option to content type form.
$form['workflow']['language_content_type']['#options'][TRANSLATION_ENABLED] = t('Enabled, with translation'); $form['workflow']['node_type_language']['#type'] = 'radios';
// Description based on text from locale.module. $form['workflow']['node_type_language']['#options'] = array(t('Disabled'), t('Enabled'), TRANSLATION_ENABLED => t('Enabled, with translation'));
$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'))); // 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) { ...@@ -475,7 +476,7 @@ function translation_node_get_translations($tnid) {
* Boolean value. * Boolean value.
*/ */
function translation_supported_type($type) { 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;
} }
/** /**
......
...@@ -38,7 +38,7 @@ class TranslationTestCase extends DrupalWebTestCase { ...@@ -38,7 +38,7 @@ class TranslationTestCase extends DrupalWebTestCase {
// translation. // translation.
$this->drupalGet('admin/structure/types/manage/page'); $this->drupalGet('admin/structure/types/manage/page');
$edit = array(); $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->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.')); $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 { ...@@ -231,7 +231,7 @@ class TranslationTestCase extends DrupalWebTestCase {
// Disable translation support to check that the language switcher is left // Disable translation support to check that the language switcher is left
// untouched only for new nodes. // untouched only for new nodes.
$this->drupalLogin($this->admin_user); $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->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
$this->drupalLogin($this->translator); $this->drupalLogin($this->translator);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment