diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 9ee58fc350e36922a249469140914cb209808e86..e35350123845555318be6f9484ffb4690c427e3d 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -448,6 +448,7 @@ function comment_node_links_alter(array &$node_links, NodeInterface $node, array if (user_access('post comments')) { $links['comment-add'] = array( 'title' => t('Add new comment'), + 'language' => $node->language(), 'attributes' => array('title' => t('Add a new comment to this page.')), 'fragment' => 'comment-form', ); diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocalePathTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocalePathTest.php index 62aba310e380e5e99555e05b0e65676d56465877..4466a91a7d6d031f64e1d7bf0d6d6ac8bfdf80fc 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocalePathTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocalePathTest.php @@ -117,14 +117,14 @@ function testPathLanguageConfiguration() { $this->container->get('path.crud')->delete($edit); // Create language nodes to check priority of aliases. - $first_node = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1)); - $second_node = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1)); + $first_node = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1, 'langcode' => 'en')); + $second_node = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1, 'langcode' => Language::LANGCODE_NOT_SPECIFIED)); // Assign a custom path alias to the first node with the English language. $edit = array( 'source' => 'node/' . $first_node->id(), 'alias' => $custom_path, - 'langcode' => 'en', + 'langcode' => $first_node->language()->id, ); $this->container->get('path.crud')->save($edit['source'], $edit['alias'], $edit['langcode']); @@ -132,7 +132,7 @@ function testPathLanguageConfiguration() { $edit = array( 'source' => 'node/' . $second_node->id(), 'alias' => $custom_path, - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, + 'langcode' => $second_node->language()->id, ); $this->container->get('path.crud')->save($edit['source'], $edit['alias'], $edit['langcode']); diff --git a/core/modules/node/lib/Drupal/node/NodeViewBuilder.php b/core/modules/node/lib/Drupal/node/NodeViewBuilder.php index 48fb0ffcf1483800094c7db4c408c78ad3670121..34ca5deac92514b52de6f1d11a2735232b1ee183 100644 --- a/core/modules/node/lib/Drupal/node/NodeViewBuilder.php +++ b/core/modules/node/lib/Drupal/node/NodeViewBuilder.php @@ -95,7 +95,7 @@ public static function renderLinks(array $context) { ); if (!$context['in_preview']) { - $entity = entity_load('node', $context['node_entity_id']); + $entity = entity_load('node', $context['node_entity_id'])->getTranslation($context['langcode']); $links['node'] = self::buildLinks($entity, $context['view_mode']); // Allow other modules to alter the node links. @@ -132,6 +132,7 @@ protected static function buildLinks(NodeInterface $entity, $view_mode) { '@title' => $node_title_stripped, )), 'href' => 'node/' . $entity->id(), + 'language' => $entity->language(), 'html' => TRUE, 'attributes' => array( 'rel' => 'tag', diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php index e78b5bc58e4b5421469ae62d7221b9419c06426a..f227792dee2927847ae67ae9ff9517e83abfadee 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php @@ -154,6 +154,7 @@ protected function assertTaxonomyPage($is_admin) { $this->drupalGet("taxonomy/term/$tid"); $this->nids_visible = array(); foreach ($this->xpath("//a[text()='Read more']") as $link) { + // See also testTranslationRendering() in NodeTranslationUITest. $this->assertTrue(preg_match('|node/(\d+)$|', (string) $link['href'], $matches), 'Read more points to a node'); $this->nids_visible[$matches[1]] = TRUE; } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php index 1a15c55cff8cefd0b135409759626a954090c70a..afc0c570710f89f55222cb4c2601f49e9c9ae5e2 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php @@ -271,6 +271,53 @@ function testTranslationRendering() { $this->assertText($values[$langcode]['title'][0]['value']); } + // Need to check from the beginning, including the base_path, in the url + // since the pattern for the default language might be a substring of + // the strings for other languages. + $base_path = base_path(); + + // Check the frontpage for 'Read more' links to each translation. + // See also assertTaxonomyPage() in NodeAccessBaseTableTest. + $node_href = 'node/' . $node->id(); + foreach ($this->langcodes as $langcode) { + $num_match_found = 0; + if ($langcode == 'en') { + // Site default language does not have langcode prefix in the URL. + $expected_href = $base_path . $node_href; + } + else { + $expected_href = $base_path . $langcode . '/' . $node_href; + } + $pattern = '|^' . $expected_href . '$|'; + foreach ($this->xpath("//a[text()='Read more']") as $link) { + if (preg_match($pattern, (string) $link['href'], $matches) == TRUE) { + $num_match_found++; + } + } + $this->assertTrue($num_match_found == 1, 'There is 1 Read more link, ' . $expected_href . ', for the ' . $langcode . ' translation of a node on the frontpage. (Found ' . $num_match_found . '.)'); + } + + // Check the frontpage for 'Add new comment' links that include the + // language. + $comment_form_href = 'node/' . $node->id() . '#comment-form'; + foreach ($this->langcodes as $langcode) { + $num_match_found = 0; + if ($langcode == 'en') { + // Site default language does not have langcode prefix in the URL. + $expected_href = $base_path . $comment_form_href; + } + else { + $expected_href = $base_path . $langcode . '/' . $comment_form_href; + } + $pattern = '|^' . $expected_href . '$|'; + foreach ($this->xpath("//a[text()='Add new comment']") as $link) { + if (preg_match($pattern, (string) $link['href'], $matches) == TRUE) { + $num_match_found++; + } + } + $this->assertTrue($num_match_found == 1, 'There is 1 Add new comment link, ' . $expected_href . ', for the ' . $langcode . ' translation of a node on the frontpage. (Found ' . $num_match_found . '.)'); + } + // Test that the node page displays the correct translations. $this->doTestTranslations('node/' . $node->id(), $values); } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 63c2174dbc193c33f3b37afe999a826641744d50..66145b02c7fae3a216a9f7dcdda4c95fd852ea75 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -644,7 +644,9 @@ function template_preprocess_node(&$variables) { ); $variables['name'] = drupal_render($username); - $variables['node_url'] = $node->url(); + $variables['node_url'] = $node->url('canonical', array( + 'language' => $node->language(), + )); $variables['label'] = $variables['elements']['title']; unset($variables['elements']['title']); $variables['page'] = $variables['view_mode'] == 'full' && node_is_page($node);