Problem/Motivation

When using URL based language detection using domain, the default path can not be empty. The help text on the settings page states that, the domain field can be

Proposed resolution

Remove the line from the settings screen as suggested by gabor-hojtsy in #5

Remaining tasks

create patch to remove / alter the line, saying "Leave blank for the default language.", noting that the domain for the default language can not be empty. This is done.
change the form validation, so that a domain can not be empty for any language. This is done.
Need manual tests and screen shots.This is done.

User interface changes

before:
before
after:
after

Original report by @greg-sims

I created a new website based on 8.0.0-alpha15. The site was loaded in English and I added Spanish. "Detection and selection" uses URL configured for "Domain" as follows:

  • English: Blank per the instructions on the configuration page for the default site. "Leave blank for the default language."
  • Spanish: es.raystedman.info

I then enabled the "Language switcher" block on the "First sidebar".

I created content in English and translated it to Spanish. When the English version is displayed and Spanish is clicked in the Language switcher block, everything works as expected -- the Spanish version of the content is displayed with URL: http://es.raystedman.info/devocionales-diarios/efesios/a-la-vista

Here is the issue. When the Spanish version of the content is displayed and English is clicked in the Language switcher block, the URL created is not correct. The URL displayed is: http://es.raystedman.info/daily-devotions/ephesians/on-display. Everything is correct with this URL except for the sub-domain. The sub-domain should be that of the default language which is English -- not es for Spanish.

The big question is what is sub-domain of the default English language? Please recall it is configured as blank per the directions in the "detection and selection" configuration page as mentioned above. When English is changed to "www.raystedman.info" everything works as expected. The solution to this problem could be as easy updating the configuration page documentation.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Gábor Hojtsy’s picture

Title: Language Switcher for Default Language » Language domain may not be left blank for default language
Issue tags: +D8MI, +language-base

I am not sure where the domain is taken when on a translated domain. I mean how would Drupal tell which domain to use? Whether it is en.x.y.z or just x.y.z? Just specify the value for default language and let's see if that works. If so, we should fix the docs.

Gábor Hojtsy’s picture

Status: Active » Postponed (maintainer needs more info)
Greg Sims’s picture

FileSize
122.95 KB

The big question is what is sub-domain of the default English language? Please recall it is configured as blank per the directions in the "detection and selection" configuration page as mentioned above. When English is changed to "www.raystedman.info" everything works as expected. The solution to this problem could be as easy updating the configuration page documentation.

Please see the attached screenshot of the "Configure URL language negotiation" page that might need to be changed.

Greg Sims’s picture

Status: Postponed (maintainer needs more info) » Active
Gábor Hojtsy’s picture

Right I believe the docs are not correct. Drupal has no way to tell the default domain unless provided. Can you help with a patch? Should just remove that sentence AFAIS.

Gábor Hojtsy’s picture

Issue tags: +Novice
pefferen’s picture

Issue tags: +Amsterdam2014
pefferen’s picture

Issue summary: View changes
pefferen’s picture

We changed the form alter, to check for a domain for each language. In addition the description on the form is altered and the error message, on the form validate is altered aswell. see the attached patch.

pefferen’s picture

Status: Active » Needs review
pefferen’s picture

Issue summary: View changes

Status: Needs review » Needs work
alimac’s picture

I'm looking at why this patch failed testing.

YesCT’s picture

@alimac said is going to try and run the tests locally to get some more info.

-

1.

+++ b/core/modules/language/src/Form/NegotiationUrlForm.php
@@ -130,10 +130,10 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
           // Throw a form error if the domain is blank for a non-default language,
           // although it is required for selected negotiation type.

this comment needs to change also.

2.
there are no changes to tests. Maybe we did not have test about this? Or maybe we did and now they are failing cause we did not update them...

Maybe those tests were not setting the default domain. and so now there is an exception thrown during the tests.

3.
It might be interesting to do a git blame on those lines which say it may be blank to try and find out why we thought it would be a good idea to allow no value.

alimac’s picture

Status: Needs work » Needs review
FileSize
2.31 KB

I ran tests locally and a lot more of them failed. Running tests again to see if the results will be consistent.

Status: Needs review » Needs work
alimac’s picture

Status: Needs work » Needs review
FileSize
3.03 KB
740 bytes

This patch will most likely fail, but it should fail a smaller number of tests than the previous patch.

We should add a test for when the exception is thrown (that is, when the domain for default language is not specified). Also, noticed some typos in the doc blocks.

Status: Needs review » Needs work
alimac’s picture

Status: Needs work » Needs review
FileSize
3.03 KB
778 bytes

Test failed earlier because we supplied an explicit default hostname (en.example.com). Instead, since we don't know the hostname, let's try using gethostname() to determine the current hostname.

Status: Needs review » Needs work
alimac’s picture

+++ b/core/modules/language/src/Form/NegotiationUrlForm.php
@@ -59,7 +59,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
+      '#description' => $this->t('The domain names to use for these languages. The domain may not be left blank. Use with caution in a production environment.<strong>Modifying this value may break existing URLs. Use with caution in a production environment.</strong> Example: Specifying "de.example.com" as language domain for German will result in an URL like "http://de.example.com/contact".'),

"Use with caution.." is repeated twice.
Previously, "Leave blank" used active voice, so we should also use active voice: https://www.drupal.org/style-guide/content#voice
Maybe: Don't leave the domain blank.

alimac’s picture

This patch has the fix for the remaining test (LanguageUrlRewritingTest) and also updated text of the description.

Still need to see about writing a test for leaving the domain field blank.

alimac’s picture

Here's a test to make sure that if you leaven the domain field blank, it will throw an error.

alimac’s picture

Fixed a whitespace issue and added an assertion for the test in which configuration is saved successfully.

Adding a test-only patch that should fail.

Status: Needs review » Needs work
alimac’s picture

Status: Needs work » Needs review

Good. The patch passed and the test-only patch failed with the expected message.

realityloop’s picture

Issue tags: +Needs manual testing
xadag’s picture

I'm working on this issue

Sutharsan’s picture

@xadag Please assign the issue to yourself while working on an issue. It will prevent others to start woking on the issue.

alimac’s picture

@Sutharsan new contributors often work together on issues, so we don't assign issues. Instead we post comments to communicate what we are going to do ("I am going to manually test this patch at the DrupalCon Amsterdam mentored sprint" for example.)

Sutharsan’s picture

Ok, thanks.

xadag’s picture

Assigned: Unassigned » xadag
xadag’s picture

Assigned: xadag » Unassigned
pp’s picture

Assigned: Unassigned » pp
xadag’s picture

Hello,

I've reviewed the latest two patches (full one and only testing one).
Everything is fine for me, process and code, when now i'm viewing a translated node in english and switched to spanish with the language selector, i've the correct version and domain displayed.

When i'm trying to submit the configuration of detection domain with blank domain for default language, i've got an error so everything it's fine.

pp’s picture

FileSize
53.38 KB

I tried the patch.
Switch on the language module.
Add a Hungarian language
Go to Configure URL language negotiation page.
Change "Part of the URL that determines language" to "Domain"
Save empty fields.

Without patch, I can save emty English domain. With patch I got a following error:

I saw the correct error messages

No, I will check the code, and if I do not find any issue, I put it to rtbc

pp’s picture

The line:

'domain[en]' => gethostname(),

missing in test only patch.

I reroll that patch and waiting for testbot.
Anything else looking good for me.

If it will be FAILED, I put it to RTBC

pp’s picture

Assigned: pp » Unassigned

oooh... I must to goo. Anybody else must put it to RTBC, sorry

alimac’s picture

@pp

The test-only patch is supposed to only add the assertion, and not the 'domain[en]' => gethostname() part, because it's testing what happens when the domain for the default language (in this case 'en') is left blank.

marcus7777’s picture

FileSize
1.4 KB

We wanted to see to see what changed from the test only patch in the #24 to the the test only patch in #37.
I made the interdiff by applying the patch no #24 the 8.0.x on branch 24 then switching back to 8.0.x and applying patch no #37 and running a diff between the two branches.

Gábor Hojtsy’s picture

No the test only patch needs to be equal to the test changes of the complete fix. Otherwise how do you know that it properly fails? The test looks good, it has coverage for both empty and filled in domains, it should properly fail without the fix. It *should not* be a different test.

Already done in #37 so no need to set to needs work.

rudivanes’s picture

So I used the test module to run the 2 tests changed by this patch and also did a manual test. And the output by the test module was ok for the empty domain issue.
However another testline returned a failure. I guess it can be caused by my local environment not allowing it.example.com. I don't know if this is relevant.
If not. I think it is RTBC.

P.S. I've added a screenshot of the test moduel output.

Sutharsan’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Please update the tags and the issue summary, specifically the remaining tasks.

+++ b/core/modules/language/src/Form/NegotiationUrlForm.php
@@ -59,7 +59,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
-      '#description' => $this->t('The domain names to use for these languages. Leave blank for the default language. Use with caution in a production environment.<strong>Modifying this value may break existing URLs. Use with caution in a production environment.</strong> Example: Specifying "de.example.com" as language domain for German will result in an URL like "http://de.example.com/contact".'),
...
       '#states' => array(

I do not like the double negative in: "Do not leave the domain blank." Either make it a positive sentence about required values or remove this part completely as its added value is limited.

marcus7777’s picture

Status: Needs work » Needs review
Issue tags: -Needs issue summary update
FileSize
1.23 KB
4.34 KB

removed 'Do not leave the domain blank.' per #43

marcus7777’s picture

Issue summary: View changes
rudivanes’s picture

A am manualy testing this right now.

rudivanes’s picture

FileSize
84.49 KB

Here is the screenshot of manual testing before applying patch #44.

Xano’s picture

+++ b/core/modules/language/src/Form/NegotiationUrlForm.php
@@ -59,7 +59,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
-      '#description' => $this->t('The domain names to use for these languages. Leave blank for the default language. Use with caution in a production environment.<strong>Modifying this value may break existing URLs. Use with caution in a production environment.</strong> Example: Specifying "de.example.com" as language domain for German will result in an URL like "http://de.example.com/contact".'),
+      '#description' => $this->t('The domain names to use for these languages. <strong>Modifying this value may break existing URLs. Use with caution in a production environment.</strong> Example: Specifying "de.example.com" as language domain for German will result in an URL like "http://de.example.com/contact".'),

If the value field is no longer optional, shouldn't we add '#required' => TRUE, here?

marcus7777’s picture

FileSize
46.89 KB

screen shot after:
after #44 patch

alimac’s picture

FileSize
84.49 KB

@Xano The field cannot be required at this point because the domain fields are hidden and only appear when the user selects Domain radio button. (This form could be refactored but that's outside of the scope of this issue.)

rudivanes’s picture

Tested the before and after situation manually. The test went succesfully.
Before applying the patch leaving the english domain empty was allowed.
After applying the patch #44 it wasn't allowed and the correct error message was displayed.

marcus7777’s picture

Issue summary: View changes
Xano’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs manual testing

@Xano The field cannot be required at this point because the domain fields are hidden and only appear when the user selects Domain radio button. (This form could be refactored but that's outside of the scope of this issue.)

Thanks! It makes total sense not to mark this field as required.

Manual testing was done in #52. Multiple people have confirmed the patch works, that this approach is the right one, and that the test coverage is sufficient. The code looks good. This is good to go!

ricardoamaro’s picture

I' tested this on:
http://testbot.drupal-pt.org/node/404

You have the results here with 1 fail:
http://testbot.drupal-pt.org/sites/default/files/build_D80x_mysql55_PHP5...

Also you can have the results suite from:
http://testbot.drupal-pt.org/sites/default/files/build_D80x_mysql55_PHP5...

Tested:
DCI_TESTGROUPS="language,locale,system"

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.0.x. LIVE FROM DRUPALCON! :D

  • webchick committed 76b8f62 on 8.0.x
    Issue #2343943 by marcus7777, pp, alimac, pefferen | Greg Sims: Fixed...
Schnitzel’s picture

  • alexpott committed 853741a on 8.0.x
    Issue #2350543 by Schnitzel: Fixed #2343943 introduced gethostname(),...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.