Commit 0a8e34cf authored by alexpott's avatar alexpott

Issue #2149649 by Gábor Hojtsy, YesCT, Xano, herom, vijaycs85, Sweetchuck,...

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.
parent 4ac79a13
......@@ -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',
);
......
......@@ -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']);
......
......@@ -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',
......
......@@ -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;
}
......
......@@ -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);
}
......
......@@ -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);
......
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