Skip to content
Snippets Groups Projects
Commit 08f59215 authored by Angie Byron's avatar Angie Byron
Browse files

#518364 by plach, neochief, Ryan Palmer: Fixed Nodes with one language don't...

#518364 by plach, neochief, Ryan Palmer: Fixed Nodes with one language don't affect the language switcher block.
parent 14d19b22
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -923,7 +923,8 @@ function locale_block_view($type) {
$path = drupal_is_front_page() ? '<front>' : $_GET['q'];
$links = language_negotiation_get_switch_links($type, $path);
if (isset($links->links) && count($links->links > 1)) {
if (isset($links->links)) {
drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css');
$class = "language-switcher-{$links->provider}";
$variables = array('links' => $links->links, 'attributes' => array('class' => array($class)));
$block['content'] = theme('links__locale_block', $variables);
......
......@@ -484,7 +484,7 @@ function translation_supported_type($type) {
function translation_path_get_translations($path) {
$paths = array();
// Check for a node related path, and for its translations.
if ((preg_match("!^node/([0-9]+)(/.+|)$!", $path, $matches)) && ($node = node_load((int)$matches[1])) && !empty($node->tnid)) {
if ((preg_match("!^node/(\d+)(/.+|)$!", $path, $matches)) && ($node = node_load((int) $matches[1])) && !empty($node->tnid)) {
foreach (translation_node_get_translations($node->tnid) as $language => $translation_node) {
$paths[$language] = 'node/' . $translation_node->nid . $matches[2];
}
......@@ -499,18 +499,18 @@ 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 && $paths = translation_path_get_translations($path)) {
$path = explode('/', $path);
$node = node_load($path[1]);
$translations = translation_node_get_translations($node->tnid);
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);
foreach ($links as $langcode => $link) {
if (isset($paths[$langcode]) && $translations[$langcode]->status) {
if (isset($translations[$langcode]) && $translations[$langcode]->status) {
// Translation in a different node.
$links[$langcode]['href'] = $paths[$langcode];
$links[$langcode]['href'] = 'node/' . $translations[$langcode]->nid . $matches[2];
}
else {
// No translation in this language, or no permission to view.
unset($links[$langcode]);
unset($links[$langcode]['href']);
$links[$langcode]['attributes']['class'] = 'locale-untranslated';
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment