summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGábor Hojtsy2013-04-09 14:56:54 (GMT)
committer Gábor Hojtsy2013-04-09 14:56:54 (GMT)
commit369717ca0197157a4cac25594be2ecedeb4e498b (patch)
treedaa1af5546bd5b6a8afc940f182200e54259b9d9
parent1010f68d843eb350a0b27dbed0c1d8722ba49bb4 (diff)
Issue #1936194 by vijaycs85, Gábor Hojtsy: Don't support translations of langcode = und config.
-rw-r--r--config_translation.module10
-rw-r--r--lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php44
2 files changed, 50 insertions, 4 deletions
diff --git a/config_translation.module b/config_translation.module
index 008e80c..e3d20b8 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 119a81d..1840763 100644
--- a/lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php
+++ b/lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php
@@ -248,6 +248,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.
*
* @param string $site_name