diff options
author | Dries Buytaert <dries@buytaert.net> | 2011-05-13 16:01:59 -0400 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2011-05-13 16:01:59 -0400 |
commit | 3035021f74b01b2a0747610e6589df902d12137a (patch) | |
tree | 95f9628e94de4ba23e6dc73ceace2ff875fa1386 /modules/translation | |
parent | 148569d98637b952c6aacb8bc28a9fd8c3211d84 (diff) | |
download | brdo-3035021f74b01b2a0747610e6589df902d12137a.tar.gz brdo-3035021f74b01b2a0747610e6589df902d12137a.tar.bz2 |
- Patch #1060246 by plach: translation alters language switch links even if node translation is disabled.
Diffstat (limited to 'modules/translation')
-rw-r--r-- | modules/translation/translation.module | 19 | ||||
-rw-r--r-- | modules/translation/translation.test | 38 |
2 files changed, 53 insertions, 4 deletions
diff --git a/modules/translation/translation.module b/modules/translation/translation.module index e0ee18ff7..1fd12a5ee 100644 --- a/modules/translation/translation.module +++ b/modules/translation/translation.module @@ -502,8 +502,23 @@ function translation_path_get_translations($path) { */ function translation_language_switch_links_alter(array &$links, $type, $path) { $language_type = variable_get('translation_language_type', LANGUAGE_TYPE_INTERFACE); - if ($type == $language_type && preg_match("!^node/(\d+)(/.+|)!", $path, $matches) && ($node = node_load((int) $matches[1]))) { - $translations = $node->tnid ? translation_node_get_translations($node->tnid) : array($node->language => $node); + + if ($type == $language_type && preg_match("!^node/(\d+)(/.+|)!", $path, $matches)) { + $node = node_load((int) $matches[1]); + + if (empty($node->tnid)) { + // If the node cannot be found nothing needs to be done. If it does not + // have translations it might be a language neutral node, in which case we + // must leave the language switch links unaltered. This is true also for + // nodes not having translation support enabled. + if (empty($node) || $node->language == LANGUAGE_NONE || !translation_supported_type($node->type)) { + return; + } + $translations = array($node->language => $node); + } + else { + $translations = translation_node_get_translations($node->tnid); + } foreach ($links as $langcode => $link) { if (isset($translations[$langcode]) && $translations[$langcode]->status) { diff --git a/modules/translation/translation.test b/modules/translation/translation.test index f57875049..c4a04c4cf 100644 --- a/modules/translation/translation.test +++ b/modules/translation/translation.test @@ -204,6 +204,38 @@ class TranslationTestCase extends DrupalWebTestCase { $this->assertLanguageSwitchLinks($node, $node, TRUE, $type); $this->assertLanguageSwitchLinks($node, $translation_es, TRUE, $type); $this->assertLanguageSwitchLinks($node, $translation_it, TRUE, $type); + + // Create a language neutral node and check that the language switcher is + // left untouched. + $node2 = $this->createPage($this->randomName(), $this->randomName(), LANGUAGE_NONE); + $node2_en = (object) array('nid' => $node2->nid, 'language' => 'en'); + $node2_es = (object) array('nid' => $node2->nid, 'language' => 'es'); + $node2_it = (object) array('nid' => $node2->nid, 'language' => 'it'); + $this->assertLanguageSwitchLinks($node2_en, $node2_en, TRUE, $type); + $this->assertLanguageSwitchLinks($node2_en, $node2_es, TRUE, $type); + $this->assertLanguageSwitchLinks($node2_en, $node2_it, TRUE, $type); + + // Disable translation support to check that the language switcher is left + // untouched only for new nodes. + $this->drupalLogin($this->admin_user); + $edit = array('language_content_type' => 0); + $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); + $this->drupalLogin($this->translator); + + // Existing translations trigger alterations even if translation support is + // disabled. + $this->assertLanguageSwitchLinks($node, $node, TRUE, $type); + $this->assertLanguageSwitchLinks($node, $translation_es, TRUE, $type); + $this->assertLanguageSwitchLinks($node, $translation_it, TRUE, $type); + + // Check that new nodes with a language assigned do not trigger language + // switcher alterations when translation support is disabled. + $node = $this->createPage($this->randomName(), $this->randomName()); + $node_es = (object) array('nid' => $node->nid, 'language' => 'es'); + $node_it = (object) array('nid' => $node->nid, 'language' => 'it'); + $this->assertLanguageSwitchLinks($node, $node, TRUE, $type); + $this->assertLanguageSwitchLinks($node, $node_es, TRUE, $type); + $this->assertLanguageSwitchLinks($node, $node_it, TRUE, $type); } /** @@ -268,12 +300,14 @@ class TranslationTestCase extends DrupalWebTestCase { * @param * $language Language code. */ - function createPage($title, $body, $language) { + function createPage($title, $body, $language = NULL) { $edit = array(); $langcode = LANGUAGE_NONE; $edit["title"] = $title; $edit["body[$langcode][0][value]"] = $body; - $edit['language'] = $language; + if (!empty($language)) { + $edit['language'] = $language; + } $this->drupalPost('node/add/page', $edit, t('Save')); $this->assertRaw(t('Basic page %title has been created.', array('%title' => $title)), t('Basic page created.')); |