Skip to content
Snippets Groups Projects
Commit 8ffe09ee authored by Katherine Bailey's avatar Katherine Bailey
Browse files

Clarifying the _current_path() problem as it relates to path alias caching and...

Clarifying the _current_path() problem as it relates to path alias caching and making the request param non-optional in language_from_url
parent b979e8aa
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
......@@ -214,18 +214,16 @@ function drupal_cache_system_paths() {
$cache = &drupal_static('drupal_lookup_path', array());
if (empty($cache['system_paths']) && !empty($cache['map'])) {
// @todo Because caching happens during $kernel->terminate(), i.e.
// after we have left the scope of the Request, the call to current_path()
// here does not return the system path, and instead calls out to
// _current_path(), which returns the alias. So the alias gets used as the
// key instead. At lookup time, whether the alias or the source is used as
// the key depends on when the first call to url() is made for that path.
// If this is within the request scope, it uses the system_path and so will
// be a cache miss. There is a separate issue for fixing up the path alias
// logic here: http://drupal.org/node/1269742
// @todo Because we are not within the request scope at this time, we cannot
// use current_path(), which would give us the system path to use as the
// key. Instead we call _current_path(), which may give us the alias
// instead. However, at lookup time the system path will be used as the
// key, because it uses current_path(), and so it will be a cache miss.
// There is a critical issue for fixing the path alias logic here:
// http://drupal.org/node/1269742
// Generate a cache ID (cid) specifically for this page.
$cid = current_path();
$cid = _current_path();
// The static $map array used by drupal_lookup_path() includes all
// system paths for the page request.
if ($paths = current($cache['map'])) {
......@@ -369,11 +367,14 @@ function drupal_match_path($path, $patterns) {
* @see request_path()
*/
function current_path() {
// @todo Remove the check for whether the request service exists and the
// fallback code below, once the path alias logic has been figured out in
// http://drupal.org/node/1269742.
if (drupal_container()->has('request')) {
return drupal_container()->get('request')->attributes->get('system_path');
}
// If we are outside the request scope, e.g. during $kernel->terminate, fall
// back to using the path stored in _current_path().
// If we are outside the request scope, fall back to using the path stored in
// _current_path().
return _current_path();
}
......
......@@ -197,10 +197,13 @@ function language_from_session($languages) {
* @param $languages
* An array of valid language objects.
*
* @param $request
* The HttpRequest object representing the current request.
*
* @return
* A valid language code on success, FALSE otherwise.
*/
function language_from_url($languages, $request = NULL) {
function language_from_url($languages, $request) {
$language_url = FALSE;
if (!language_negotiation_method_enabled(LANGUAGE_NEGOTIATION_URL)) {
......@@ -209,23 +212,17 @@ function language_from_url($languages, $request = NULL) {
switch (variable_get('language_negotiation_url_part', LANGUAGE_NEGOTIATION_URL_PREFIX)) {
case LANGUAGE_NEGOTIATION_URL_PREFIX:
// Language negotiation happens before the public function current_path()
// is available.
// @todo Refactor with Symfony's Request object.
if ($request) {
$current_path = $request->attributes->get('system_path');
if (!isset($current_path)) {
$current_path = trim($request->getPathInfo(), '/');
}
}
else {
$current_path = _current_path();
$current_path = $request->attributes->get('system_path');
if (!isset($current_path)) {
$current_path = trim($request->getPathInfo(), '/');
}
list($language, $path) = language_url_split_prefix($current_path, $languages);
if ($request) {
$request->attributes->set('system_path', $path);
}
// Store the correct system path, i.e. minus the path prefix, in the
// request.
$request->attributes->set('system_path', $path);
if ($language !== FALSE) {
$language_url = $language->langcode;
}
......
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