diff --git a/core/includes/language.inc b/core/includes/language.inc index b2ec7df..a3cb3c8 100644 --- a/core/includes/language.inc +++ b/core/includes/language.inc @@ -212,7 +212,8 @@ function language_negotiation_get_switch_links($type, $path) { } /** - * Updates language configuration to remove any language provider that is no longer defined. + * Updates language configuration to remove any language provider that is no + * longer defined. */ function language_negotiation_purge() { // Ensure that we are getting the defined language negotiation information. An diff --git a/core/includes/locale.inc b/core/includes/locale.inc index 4cd0c59..b6d7330 100644 --- a/core/includes/locale.inc +++ b/core/includes/locale.inc @@ -510,6 +510,12 @@ function locale_language_url_rewrite_session(&$path, &$options) { $options['query'][$query_param] = $query_value; } } + + // Change the global language variable if not exists yet. + if (!isset($options['language'])) { + global $language; + $options['language'] = $language; + } } /** diff --git a/core/includes/path.inc b/core/includes/path.inc index 1fac235..fefc95d 100644 --- a/core/includes/path.inc +++ b/core/includes/path.inc @@ -43,7 +43,7 @@ function drupal_path_initialize() { * found. */ function drupal_lookup_path($action, $path = '', $path_language = NULL) { - global $language_url; + global $language; // Use the advanced drupal_static() pattern, since this is called very often. static $drupal_static_fast; if (!isset($drupal_static_fast)) { @@ -74,7 +74,7 @@ function drupal_lookup_path($action, $path = '', $path_language = NULL) { // language. If we used a language different from the one conveyed by the // requested URL, we might end up being unable to check if there is a path // alias matching the URL path. - $path_language = $path_language ? $path_language : $language_url->language; + $path_language = $path_language ? $path_language : $language->language; if ($action == 'wipe') { $cache = array(); diff --git a/core/modules/translation/translation.module b/core/modules/translation/translation.module index 9f6a6d5..dddeb8d 100644 --- a/core/modules/translation/translation.module +++ b/core/modules/translation/translation.module @@ -522,8 +522,9 @@ function translation_language_switch_links_alter(array &$links, $type, $path) { foreach ($links as $langcode => $link) { if (isset($translations[$langcode]) && $translations[$langcode]->status) { - // Translation in a different node. - $links[$langcode]['href'] = 'node/' . $translations[$langcode]->nid . $matches[2]; + // Translation in a different node, try getting its alias if exists. + $link_path = drupal_get_path_alias('node/' . $translations[$langcode]->nid . $matches[2], $langcode); + $links[$langcode]['href'] = $link_path; } else { // No translation in this language, or no permission to view. diff --git a/core/modules/translation/translation.test b/core/modules/translation/translation.test index 0e801c1..a9ec061 100644 --- a/core/modules/translation/translation.test +++ b/core/modules/translation/translation.test @@ -17,10 +17,10 @@ class TranslationTestCase extends DrupalWebTestCase { } function setUp() { - parent::setUp('locale', 'translation', 'translation_test'); + parent::setUp('locale', 'path', 'translation', 'translation_test'); // Setup users. - $this->admin_user = $this->drupalCreateUser(array('bypass node access', 'administer nodes', 'administer languages', 'administer content types', 'administer blocks', 'access administration pages', 'translate content')); + $this->admin_user = $this->drupalCreateUser(array('bypass node access', 'administer nodes', 'administer languages', 'administer content types', 'administer blocks', 'access administration pages', 'translate content', 'administer url aliases', 'create url aliases')); $this->translator = $this->drupalCreateUser(array('create page content', 'edit own page content', 'translate content')); $this->drupalLogin($this->admin_user); @@ -57,6 +57,60 @@ class TranslationTestCase extends DrupalWebTestCase { $this->drupalLogin($this->translator); } + function testTranslationAlias() { + // Create Basic page in English. + $node_title = $this->randomName(); + $node_body = $this->randomName(); + $node = $this->createPage($node_title, $node_body, 'en'); + + // Submit translation in Spanish. + $node_translation_title = $this->randomName(); + $node_translation_body = $this->randomName(); + $node_translation = $this->createTranslation($node, $node_translation_title, $node_translation_body, 'es'); + + // Login as admin to create aliases. + $this->drupalLogin($this->admin_user); + + // Create a path alias in default language (English). + $path = 'admin/config/search/path/add'; + $translated_path = $this->randomName(8); + $prefix = 'es'; + $edit = array( + 'source' => 'node/' . $node_translation->nid, + 'alias' => $translated_path, + 'language' => $prefix, + ); + $this->drupalPost($path, $edit, t('Save')); + + // Get translated node alias path, with the path prefix. + $this->drupalGet($prefix . '/' . $translated_path); + $this->assertText($node_translation->title, t('Translated node alias works with path prefix.')); + + // Enable session detection, disable url detection, this is how url + // detection works. + $edit = array( + 'language[enabled][locale-session]' => TRUE, + 'language[enabled][locale-url]' => FALSE, + 'language[weight][locale-session]' => -10, + ); + $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings')); + + // Switch language by passing language parameter, this is how session + // detection works. + $this->drupalGet('', array('query' => array('language' => $prefix))); + + // Get translated node alias. + $this->drupalGet($translated_path); + $this->assertText($node_translation->title, t('Translated node alias works with session.')); + + // Get the english node to check the translated node link. + $this->drupalGet('node/' . $node->nid); + + // Test if the alias of the translated node switch link exist. + $elements = $this->xpath('//a[@href=:href and .=:title]', array(':href' => url($translated_path), ':title' => 'Spanish')); + $this->assertTrue(!empty($elements), t('Translated node switch link has the alias as the href.')); + } + /** * Create a basic page with translation, modify the basic page outdating * translation, and update translation.