diff --git a/core/modules/language/src/Form/NegotiationUrlForm.php b/core/modules/language/src/Form/NegotiationUrlForm.php index fa1cd3e..7c824db 100644 --- a/core/modules/language/src/Form/NegotiationUrlForm.php +++ b/core/modules/language/src/Form/NegotiationUrlForm.php @@ -9,6 +9,7 @@ use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -142,14 +143,17 @@ public function validateForm(array &$form, FormStateInterface $form_state) { // Count repeated values for uniqueness check. $count = array_count_values($form_state->getValue('prefix')); + $default_langcode = $this->config('language.negotiation')->get('selected_langcode'); + if ($default_langcode == LanguageInterface::LANGCODE_SITE_DEFAULT) { + $default_langcode = $this->languageManager->getDefaultLanguage()->getId(); + } foreach ($languages as $langcode => $language) { $value = $form_state->getValue(array('prefix', $langcode)); - if ($value === '') { - if (!$language->isDefault() && $form_state->getValue('language_negotiation_url_part') == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) { + if (!($default_langcode == $langcode) && $form_state->getValue('language_negotiation_url_part') == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) { // Throw a form error if the prefix is blank for a non-default language, // although it is required for selected negotiation type. - $form_state->setErrorByName("prefix][$langcode", $this->t('The prefix may only be left blank for the default language.')); + $form_state->setErrorByName("prefix][$langcode", $this->t('The prefix may only be left blank for the negotiation selected language.')); } } elseif (strpos($value, '/') !== FALSE) { diff --git a/core/modules/language/src/Tests/LanguageConfigurationTest.php b/core/modules/language/src/Tests/LanguageConfigurationTest.php index a5efb2f..a02a189 100644 --- a/core/modules/language/src/Tests/LanguageConfigurationTest.php +++ b/core/modules/language/src/Tests/LanguageConfigurationTest.php @@ -83,13 +83,16 @@ function testLanguageConfiguration() { $this->drupalPostForm(NULL, $edit, t('Save configuration')); $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'french', 'French path prefix has changed.'); - // Check that prefix of non default language cannot be changed to - // empty string. + + // Change default negotiation language. + $this->config('language.negotiation')->set('selected_langcode', 'fr')->save(); + // Check that the prefix of a language that is not the negotiation one + // cannot be changed to empty string. $edit = array( 'prefix[en]' => '', ); $this->drupalPostForm(NULL, $edit, t('Save configuration')); - $this->assertText(t('The prefix may only be left blank for the default language.'), 'English prefix cannot be changed to empty string.'); + $this->assertText(t('The prefix may only be left blank for the negotiation selected language.'), 'Only negotiation language prefix can be changed to empty string.'); // Check that prefix cannot be changed to contain a slash. $edit = array( diff --git a/core/modules/language/src/Tests/LanguageSwitchingTest.php b/core/modules/language/src/Tests/LanguageSwitchingTest.php index 2dc0777..887f728 100644 --- a/core/modules/language/src/Tests/LanguageSwitchingTest.php +++ b/core/modules/language/src/Tests/LanguageSwitchingTest.php @@ -161,7 +161,7 @@ protected function doTestLanguageBlockAnonymous($block_label) { } /** - * Test languge switcher links for domain based negotiation + * Test language switcher links for domain based negotiation */ function testLanguageBlockWithDomain() { // Add the Italian language.