summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-03-29 11:40:21 (GMT)
committerAlex Pott2014-03-29 11:40:21 (GMT)
commit0a8e34cf15f237c0672dd6ea7776d46393467ce1 (patch)
treeb1b2f034fd35c64873434e2c592532dacfb915db
parent4ac79a1366d50ad57e0817447e60ef4c916796e0 (diff)
Issue #2149649 by Gábor Hojtsy, YesCT, Xano, herom, vijaycs85, Sweetchuck, plach: Entity rendering/theming does not use the active entity language to render links.
-rw-r--r--core/modules/comment/comment.module1
-rw-r--r--core/modules/locale/lib/Drupal/locale/Tests/LocalePathTest.php8
-rw-r--r--core/modules/node/lib/Drupal/node/NodeViewBuilder.php3
-rw-r--r--core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php1
-rw-r--r--core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php47
-rw-r--r--core/modules/node/node.module4
6 files changed, 58 insertions, 6 deletions
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 9ee58fc..e353501 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 62aba31..4466a91 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 @@ class LocalePathTest extends WebTestBase {
$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 @@ class LocalePathTest extends WebTestBase {
$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 48fb0ff..34ca5de 100644
--- a/core/modules/node/lib/Drupal/node/NodeViewBuilder.php
+++ b/core/modules/node/lib/Drupal/node/NodeViewBuilder.php
@@ -95,7 +95,7 @@ class NodeViewBuilder extends EntityViewBuilder {
);
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 @@ class NodeViewBuilder extends EntityViewBuilder {
'@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 e78b5bc..f227792 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 @@ class NodeAccessBaseTableTest extends NodeTestBase {
$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 1a15c55..afc0c57 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 @@ class NodeTranslationUITest extends ContentTranslationUITest {
$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 63c2174..66145b0 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);