Commit 826ede46 authored by webchick's avatar webchick

#356036 by plach, catch: Allow creating nodes in default languages.

parent f17797c3
......@@ -2376,6 +2376,12 @@ function language_list($field = 'language') {
if (!isset($languages)) {
if (drupal_multilingual() || module_exists('locale')) {
$languages['language'] = db_query('SELECT * FROM {languages} ORDER BY weight ASC, name ASC')->fetchAllAssoc('language');
// Users cannot uninstall the native English language. However, we allow
// it to be hidden from the installed languages. Therefore, at least one
// other language must be enabled then.
if (!$languages['language']['en']->enabled && !variable_get('language_native_enabled', TRUE)) {
unset($languages['language']['en']);
}
}
else {
// No locale module, so use the default language only.
......
......@@ -153,8 +153,7 @@ function _field_language_suggestion($available_languages, $language_suggestion,
* An array of language codes.
*/
function field_content_languages() {
$languages = language_list('enabled');
return array_keys($languages[1] + array(LANGUAGE_NONE => NULL));
return array_keys(language_list() + array(LANGUAGE_NONE => NULL));
}
/**
......
......@@ -126,6 +126,24 @@ function translation_form_node_type_form_alter(&$form, &$form_state) {
function translation_form_node_form_alter(&$form, &$form_state) {
if (translation_supported_type($form['#node']->type)) {
$node = $form['#node'];
$languages = language_list('enabled');
$disabled_languages = isset($languages[0]) ? $languages[0] : FALSE;
$translator_widget = $disabled_languages && user_access('translate content');
$groups = array(t('Disabled'), t('Enabled'));
// Allow translators to enter content in disabled languages. Translators
// might need to distinguish between enabled and disabled languages, hence
// we divide them in two option groups.
if ($translator_widget) {
$options = array();
$language_list = locale_language_list('name', TRUE);
foreach (array(1, 0) as $status) {
$group = $groups[$status];
foreach ($languages[$status] as $langcode => $language) {
$options[$group][$langcode] = $language_list[$langcode];
}
}
$form['language']['#options'] = $options;
}
if (!empty($node->translation_source)) {
// We are creating a translation. Add values and lock language field.
$form['translation_source'] = array('#type' => 'value', '#value' => $node->translation_source);
......@@ -136,9 +154,15 @@ function translation_form_node_form_alter(&$form, &$form_state) {
// node to some language which is already in the translation set. Also remove the
// language neutral option.
unset($form['language']['#options'][LANGUAGE_NONE]);
foreach (translation_node_get_translations($node->tnid) as $translation) {
foreach (translation_node_get_translations($node->tnid) as $langcode => $translation) {
if ($translation->nid != $node->nid) {
unset($form['language']['#options'][$translation->language]);
if ($translator_widget) {
$group = $groups[(int)!isset($disabled_languages[$langcode])];
unset($form['language']['#options'][$group][$langcode]);
}
else {
unset($form['language']['#options'][$langcode]);
}
}
}
// Add translation values and workflow options.
......
......@@ -83,6 +83,23 @@ class TranslationTestCase extends DrupalWebTestCase {
$edit['translation[status]'] = FALSE;
$this->drupalPost('node/' . $node_translation->nid . '/edit', $edit, t('Save'));
$this->assertRaw(t('Basic page %title has been updated.', array('%title' => $node_translation_title)), t('Translated node updated.'));
$this->drupalLogin($admin_user);
// Disable Spanish and confirm that links to the Spanish translations do
// not appear on the English node.
$edit = array();
$edit['enabled[es]'] = FALSE;
$this->drupalPost('admin/config/regional/language', $edit, t('Save configuration'));
$this->drupalGet('node/' . $node->nid);
$languages = language_list();
$this->assertNoText($languages['es']->native);
$this->drupalLogin($translator);
// Confirm that Spanish is still an option for translators when creating nodes.
$this->drupalGet('node/add/page');
$this->assertRaw('value="' . 'es' .'"', t('Spanish is available in language selection'));
}
/**
......
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