Look at LanguageUrlRewritingTest.php
and the function definition for checkUrl()
/**
* Check URL rewriting for the given language.
*
* The test is performed with a fixed URL (the default front page) to simply
* check that language prefixes are not added to it and that the prefixed URL
* is actually not working.
*
* @param string $language
* The language prefix, e.g. 'es'. <<<< THIS LINE IS WRONG!!!!
* @param string $message1
* Message to display in assertion that language prefixes are not added.
* @param string $message2
* The message to display confirming prefixed URL is not working.
*/
private function checkUrl($language, $message1, $message2) {
$options = array('language' => $language, 'script' => '');
$base_path = trim(base_path(), '/');
$rewritten_path = trim(str_replace($base_path, '', url('node', $options)), '/');
$language is used to form an options array :-
$options = [
'language' => $language,
'script' => ''
];
which is passed to the common.inc function url()
the annotations in this function comments leads me to this page
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Routing!UrlGenera...
so far so good. So quoting from this document the language key in the array should be a language object not a string!!!!
'language': An optional language object. If the path being linked to is internal to the site, $options['language'] is used to look up the alias for the URL. If $options['language'] is omitted, the language will be obtained from \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_URL).
For confirmation of this mistake please look at this functions usage. A language object $non_exising and NOT a string is passed in when the function is used.
function testUrlRewritingEdgeCases() {
// Check URL rewriting with a non-installed language.
$non_existing = \Drupal::languageManager()->getDefaultLanguage();
$non_existing->id = $this->randomMachineName();
$this->checkUrl($non_existing, 'Path language is ignored if language is not installed.', 'URL language negotiation does not work with non-installed languages');
// Check that URL rewriting is not applied to subrequests.
$this->drupalGet('language_test/subrequest');
$this->assertText($this->web_user->getUsername(), 'Page correctly retrieved');
}
Comment | File | Size | Author |
---|---|---|---|
#6 | languageParam-6.patch | 776 bytes | martin107 |
languageParam-0.patch | 775 bytes | martin107 | |
Comments
Comment #1
martin107 CreditAttribution: martin107 commentedComment #3
swentel CreditAttribution: swentel commentedComment #4
martin107 CreditAttribution: martin107 commented@swentel, sorry for the noise :(
Lets see what testbot make of this comment only patch when the the branch is correct
Comment #5
jhodgdonLooks like your conclusions are correct, and thanks for filing/investigating!
Small problem in the patch: the second line (description) should end in .
Comment #6
martin107 CreditAttribution: martin107 commentedThanks, my mistake - full stop added.
Comment #7
jhodgdonThanks! I checked this over again, and delved deep into the code. It does indeed appear that users of $options['language'] in url-generating functions expect it to be a language object, not a language code, and that is what this parameter is passed into.
Comment #8
alexpottCommitted 33a3ed6 and pushed to 8.0.x. Thanks!