Skip to content
Snippets Groups Projects
Commit a9451907 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #829968 by andypost, AlexisWilke: drupal_lookup_path() documentation and return mismatch.

parent 699afdd1
Branches
Tags
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
......@@ -131,6 +131,7 @@ function drupal_lookup_path($action, $path = '', $path_language = NULL) {
// isn't a path that has this alias
elseif ($action == 'source' && !isset($cache['no_source'][$path_language][$path])) {
// Look for the value $path within the cached $map
$source = FALSE;
if (!isset($cache['map'][$path_language]) || !($source = array_search($path, $cache['map'][$path_language]))) {
// Get the most fitting result falling back with alias without language
if ($source = db_query("SELECT source FROM {url_alias} WHERE alias = :alias AND language IN (:language, :language_none) ORDER BY language DESC, pid DESC", array(
......@@ -139,7 +140,6 @@ function drupal_lookup_path($action, $path = '', $path_language = NULL) {
':language_none' => LANGUAGE_NONE))
->fetchField()) {
$cache['map'][$path_language][$source] = $path;
return $source;
}
else {
// We can't record anything into $map because we do not have a valid
......@@ -148,6 +148,7 @@ function drupal_lookup_path($action, $path = '', $path_language = NULL) {
$cache['no_source'][$path_language][$path] = TRUE;
}
}
return $source;
}
}
......
......@@ -346,6 +346,22 @@ class PathLanguageTestCase extends DrupalWebTestCase {
// should keep working.
$this->drupalGet($french_alias);
$this->assertResponse(404, t('Alias for French translation is unavailable when URL language negotiation is disabled.'));
// drupal_lookup_path() has an internal static cache. Check to see that
// it has the appropriate contents at this point.
drupal_lookup_path('wipe');
$french_node_path = drupal_lookup_path('source', $french_alias, $french_node->language);
$this->assertEqual($french_node_path, 'node/' . $french_node->nid, t('Normal path works.'));
// Second call should return the same path.
$french_node_path = drupal_lookup_path('source', $french_alias, $french_node->language);
$this->assertEqual($french_node_path, 'node/' . $french_node->nid, t('Normal path is the same.'));
// Confirm that the alias works.
$french_node_alias = drupal_lookup_path('alias', 'node/' . $french_node->nid, $french_node->language);
$this->assertEqual($french_node_alias, $french_alias, t('Alias works.'));
// Second call should return the same alias.
$french_node_alias = drupal_lookup_path('alias', 'node/' . $french_node->nid, $french_node->language);
$this->assertEqual($french_node_alias, $french_alias, t('Alias is the same.'));
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment