Problem/Motivation
In "URL language detection configuration" at admin/config/regional/language/detection/url
, if you modify a path prefix for URL language detection under "PATH PREFIX CONFIGURATION" (while leaving the default language path prefix blank) an error message is generated:
The prefix may only be left blank for the selected detection fallback language.
This occurred both with English as the default installed language, and Spanish.
(As an aside, the motivation for modifying a prefix in this case was for simplified Chinese, where the default prefix zh-hans
is awkward.)
Screenshot with Spanish as default installed language here.
Method to replicate:
On fresh Drupal 8 install, enable multilingual modules and add language Chinese (simplified).
Go to admin/config/regional/language/detection/url
, and under "PATH PREFIX CONFIGURATION" change the path prefix for URL language detection for Chinese from zh-hans
to zh
, and click "Save Configuration".
Notes: Found on D8 Beta 9. This appears similar to, but different from, #2343943: Language domain may not be left blank for default language.
Proposed resolution
The error is caused by the default language code not being set correctly. Propose modifying 1 line of code with test for empty value of default language code.
Remaining tasks
None
User interface changes
None
API changes
None
Beta phase evaluation
Issue category | Bug because code didn't allow admin to configure language path prefixes, and returned a wrong error message. |
---|---|
Issue priority | Major because disallows basic language system configuration. |
Unfrozen changes | Not on list of unfrozen changes. |
Prioritized changes | A prioritized change, as it is a bugfix. |
Disruption | Likely no disruption, as it modifies 1 line of code logic. |
Comment | File | Size | Author |
---|---|---|---|
#10 | modifying_path_prefix-2470307-10.patch | 2.52 KB | eiriksm |
#10 | modifying_path_prefix-2470307-10-test-only.patch | 1008 bytes | eiriksm |
#9 | 2470307-default.patch | 395 bytes | Gábor Hojtsy |
#3 | modifying_path_prefix-2470307-3.patch | 899 bytes | Mark_L6n |
#2 | modifying_path_prefix-2470307-2.patch | 899 bytes | Mark_L6n |
Comments
Comment #1
Mark_L6n CreditAttribution: Mark_L6n commentedFound a solution, and will work on submitting a patch.
In file
core/modules/language/src/Form/NegotiationUrlForm.php
, variable$default_langcode
was not getting set.Comment #2
Mark_L6n CreditAttribution: Mark_L6n commentedUploaded patch
modifying_path_prefix-2470307-2.patch
.The following line was not returning a value to
$default_langcode
:$default_langcode = $this->config('language.negotiation')->get('selected_langcode');
The error was not getting caught by the subsequent test:
Testing for an empty value fixed the error:
if ($default_langcode == LanguageInterface::LANGCODE_SITE_DEFAULT || !isset($default_langcode)) {
Comment #3
Mark_L6n CreditAttribution: Mark_L6n commentedSmall improvement: reversed order in
||
statement; probably better to have!isset($default_langcode)
first.Comment #4
Mark_L6n CreditAttribution: Mark_L6n commentedComment #5
Mark_L6n CreditAttribution: Mark_L6n commentedComment #6
Mark_L6n CreditAttribution: Mark_L6n commentedComment #7
Mark_L6n CreditAttribution: Mark_L6n commentedComment #8
Anonymous (not verified) CreditAttribution: Anonymous at XIO commentedI managed to reproduce this on 8.0.x, so I'm changing the version to where it will be fixed. I don't think this should be major, but since I'm not sure, I'll leave it at that.
Thank you for the patch! However, isn't this more of a work around instead of an actual fix? I wonder why the variable isn't set?
Also we will need to add some test coverage for this. So tagging accordingly.
Comment #9
Gábor HojtsyWe can also set the value in the default config based on the default assumption. Sounds better @pjonckiere?
Also still needs tests.
Comment #10
eiriksmHeres a patch with a test included.
I also added the very minor patch i submitted over at #2486293: Create link to "selected detection fallback language" from error message. after discussion on IRC. This way, if people still have problems removing the path prefix, at least they get directed to the page where they can change it.
Also included a test-only patch (which should fail, I hope).
Comment #14
Gábor HojtsyI wanted to ask for a positive test of the message, but that seems to be already present in the existing code:
So looks great to me :)
Comment #15
alexpottCommitted 9e69588 and pushed to 8.0.x. Thanks!
Thanks for adding the beta evaluation.
Comment #17
Gábor HojtsyYay, thanks all!
Comment #19
Metal3d CreditAttribution: Metal3d as a volunteer commentedI'm sorry but I still have this issue... Drupal core 8.1.8
Each quickedit urls still have language prefix and won't work...
Comment #20
Metal3d CreditAttribution: Metal3d as a volunteer commentedChanged version, sorry
Comment #21
tamnv CreditAttribution: tamnv commentedHi all,
We still have this problem with Drupal 8.2.3.