diff --git a/config_translation.module b/config_translation.module index 008e80cad629104d71cabd66bcd0def91891b8fd..e3d20b8a20e40cdcf717c10df7e2f427c7d7c509 100644 --- a/config_translation.module +++ b/config_translation.module @@ -119,17 +119,19 @@ function config_translation_menu() { function config_translation_config_name_access(ConfigMapperInterface $mapper, $path_arg, $language = NULL) { // Get configuration group for this mapper. $group = $mapper->getConfigGroup($path_arg); + $group_language = language_load($group->getLangcode()); // Only allow access to translate configuration, if proper permissions are // granted, the configuration has translatable pieces, the source language - // is known and the target language is not the original submission language. - // Although technically config can be overlayed with translations in the same - // language, that is logically not a good idea. + // and target language are not locked, and the target language is not the + // original submission language. Although technically config can be overlayed + // with translations in the same language, that is logically not a good idea. return ( user_access('translate configuration') && $group->hasSchema() && $group->hasTranslatable() && - (empty($language) || ($language->langcode != LANGUAGE_NOT_SPECIFIED && $language->langcode != $group->getLangcode())) + !$group_language->locked && + (empty($language) || (!$language->locked && $language->langcode != $group_language->langcode)) ); } diff --git a/lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php b/lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php index 119a81d6ea3f77f1bc013f9a6324115190c1adfa..1840763fc085877ca7426e9caddc01c03eecf79c 100644 --- a/lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php +++ b/lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php @@ -247,6 +247,50 @@ class ConfigTranslationUITest extends WebTestBase { } } + /** + * Test source and target language edge cases. + */ + function testSourceAndTargetLanguage() { + // Loading translation page for not-specified language (und) + // should return 403. + $this->drupalGet('admin/config/system/site-information/translate/add/und'); + $this->assertResponse(403); + + // Check the source language doesn't have 'Add' or 'Delete' link and + // make sure source language edit goes to original configuration page + // not the translation specific edit page. + $this->drupalGet('admin/config/system/site-information/translate'); + $this->assertNoLinkByHref('admin/config/system/site-information/translate/edit/en'); + $this->assertNoLinkByHref('admin/config/system/site-information/translate/add/en'); + $this->assertNoLinkByHref('admin/config/system/site-information/translate/delete/en'); + $this->assertLinkByHref('admin/config/system/site-information'); + + // Translation addition to source language should return 403. + $this->drupalGet('admin/config/system/site-information/translate/add/en'); + $this->assertResponse(403); + + // Translation editing in source language should return 403. + $this->drupalGet('admin/config/system/site-information/translate/edit/en'); + $this->assertResponse(403); + + // Translation deletion in source language should return 403. + $this->drupalGet('admin/config/system/site-information/translate/delete/en'); + $this->assertResponse(403); + + // Set default language of site information to not-specified language (und). + config('system.site') + ->set('langcode', LANGUAGE_NOT_SPECIFIED) + ->save(); + + // Make sure translation tab does not exist on the config page. + $this->drupalGet('admin/config/system/site-information'); + $this->assertNoLinkByHref('admin/config/system/site-information/translate'); + + // If source language is not specified, translation page should be 403. + $this->drupalGet('admin/config/system/site-information/translate'); + $this->assertResponse(403); + } + /** * Helper to set site name and slogan for default language. *