Created
February 10, 2016 00:45
-
-
Save vijaycs85/ef5fa026d7efaa3ebaee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php b/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php | |
index 51f6463..8504ea9 100644 | |
--- a/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php | |
+++ b/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php | |
@@ -7,6 +7,7 @@ | |
namespace Drupal\config_translation\Access; | |
+use Drupal\config_translation\Exception\ConfigMapperLanguageException; | |
use Drupal\Core\Language\LanguageManagerInterface; | |
use Drupal\config_translation\ConfigMapperManagerInterface; | |
use Drupal\Core\Access\AccessResult; | |
@@ -74,7 +75,7 @@ public function access(RouteMatchInterface $route_match, AccountInterface $accou | |
try { | |
$langcode = $mapper->getLangcode(); | |
} | |
- catch (\RuntimeException $exception) { | |
+ catch (ConfigMapperLanguageException $exception) { | |
// ConfigTranslationController and ConfigTranslationFormBase show a | |
// helpful message if the language codes do not match, so do not let that | |
// prevent granting access. | |
diff --git a/core/modules/config_translation/src/ConfigNamesMapper.php b/core/modules/config_translation/src/ConfigNamesMapper.php | |
index 8efeb16..83c1d21 100644 | |
--- a/core/modules/config_translation/src/ConfigNamesMapper.php | |
+++ b/core/modules/config_translation/src/ConfigNamesMapper.php | |
@@ -7,6 +7,7 @@ | |
namespace Drupal\config_translation; | |
+use Drupal\config_translation\Exception\ConfigMapperLanguageException; | |
use Drupal\Core\Config\ConfigFactoryInterface; | |
use Drupal\Core\Config\TypedConfigManagerInterface; | |
use Drupal\Core\Language\LanguageInterface; | |
@@ -388,7 +389,7 @@ public function getLangcode() { | |
$langcodes = array_map([$this, 'getLangcodeFromConfig'], $this->getConfigNames()); | |
if (count(array_unique($langcodes)) > 1) { | |
- throw new \RuntimeException('A config mapper can only contain configuration for a single language.'); | |
+ throw new ConfigMapperLanguageException('A config mapper can only contain configuration for a single language.'); | |
} | |
return reset($langcodes); | |
diff --git a/core/modules/config_translation/src/Controller/ConfigTranslationController.php b/core/modules/config_translation/src/Controller/ConfigTranslationController.php | |
index 36829d2..6f277b1 100644 | |
--- a/core/modules/config_translation/src/Controller/ConfigTranslationController.php | |
+++ b/core/modules/config_translation/src/Controller/ConfigTranslationController.php | |
@@ -9,6 +9,7 @@ | |
use Drupal\config_translation\ConfigMapperManagerInterface; | |
use Drupal\config_translation\ConfigNamesMapper; | |
+use Drupal\config_translation\Exception\ConfigMapperLanguageException; | |
use Drupal\Core\Access\AccessManagerInterface; | |
use Drupal\Core\Controller\ControllerBase; | |
use Drupal\Core\Language\Language; | |
@@ -137,23 +138,8 @@ public function itemPage(Request $request, RouteMatchInterface $route_match, $pl | |
try { | |
$original_langcode = $mapper->getLangcode(); | |
} | |
- catch (\RuntimeException $exception) { | |
- $message = ''; | |
- if ($mapper instanceof ConfigNamesMapper) { | |
- $items = []; | |
- foreach ($mapper->getconfigNames() as $config_name) { | |
- $langcode = $mapper->getLangcodeFromConfig($config_name); | |
- $items[] = $config_name .': ' . $this->languageManager->getLanguage($langcode)->getName(); | |
- } | |
- $message = [ | |
- 'message' => ['#markup' => t('Configuration objects have different language codes:')], | |
- 'items' => [ | |
- '#theme' => 'item_list', | |
- '#items' => $items, | |
- ] | |
- ]; | |
- } | |
- $page['message'] = $message; | |
+ catch (ConfigMapperLanguageException $exception) { | |
+ $page['message'] = $exception->getMessageFromMapper($mapper); | |
return $page; | |
} | |
diff --git a/core/modules/config_translation/src/Exception/ConfigMapperLanguageException.php b/core/modules/config_translation/src/Exception/ConfigMapperLanguageException.php | |
index e69de29..5ead590 100644 | |
--- a/core/modules/config_translation/src/Exception/ConfigMapperLanguageException.php | |
+++ b/core/modules/config_translation/src/Exception/ConfigMapperLanguageException.php | |
@@ -0,0 +1,38 @@ | |
+<?php | |
+/** | |
+ * @file | |
+ * Contains | |
+ */ | |
+ | |
+namespace Drupal\config_translation\Exception; | |
+use Drupal\config_translation\ConfigNamesMapper; | |
+ | |
+/** | |
+ * Class ConfigMapperLanguageException | |
+ */ | |
+class ConfigMapperLanguageException extends \RuntimeException { | |
+ | |
+ /** | |
+ * @param $mapper | |
+ * | |
+ * @return array | |
+ */ | |
+ public function getMessageFromMapper($mapper) { | |
+ $message = ''; | |
+ if ($mapper instanceof ConfigNamesMapper) { | |
+ $items = []; | |
+ foreach ($mapper->getconfigNames() as $config_name) { | |
+ $langcode = $mapper->getLangcodeFromConfig($config_name); | |
+ $items[] = $config_name .': ' . $langcode; | |
+ } | |
+ $message = [ | |
+ 'message' => ['#markup' => t('Configuration objects have different language codes:')], | |
+ 'items' => [ | |
+ '#theme' => 'item_list', | |
+ '#items' => $items, | |
+ ] | |
+ ]; | |
+ } | |
+ return $message; | |
+ } | |
+} | |
\ No newline at end of file | |
diff --git a/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php | |
index 42d0b9e..e4fe134 100644 | |
--- a/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php | |
+++ b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php | |
@@ -9,6 +9,7 @@ | |
use Drupal\config_translation\ConfigMapperManagerInterface; | |
use Drupal\config_translation\ConfigNamesMapper; | |
+use Drupal\config_translation\Exception\ConfigMapperLanguageException; | |
use Drupal\Core\Config\TypedConfigManagerInterface; | |
use Drupal\Core\Render\RendererInterface; | |
use Drupal\Core\Routing\RouteMatchInterface; | |
@@ -159,22 +160,8 @@ public function buildForm(array $form, FormStateInterface $form_state, RouteMatc | |
try { | |
$langcode = $this->mapper->getLangcode(); | |
} | |
- catch (\RuntimeException $exception) { | |
- $message = ''; | |
- if ($mapper instanceof ConfigNamesMapper) { | |
- $items = []; | |
- foreach ($mapper->getconfigNames() as $config_name) { | |
- $langcode = $mapper->getLangcodeFromConfig($config_name); | |
- $items[] = $config_name .': ' . $this->languageManager->getLanguage($langcode)->getName(); | |
- } | |
- $message = [ | |
- 'message' => ['#markup' => t('Configuration objects have different language codes:')], | |
- 'items' => [ | |
- '#theme' => 'item_list', | |
- '#items' => $items, | |
- ] | |
- ]; | |
- } | |
+ catch (ConfigMapperLanguageException $exception) { | |
+ $message = $exception->getMessageFromMapper($mapper); | |
drupal_set_message($this->renderer->renderRoot($message), 'warning'); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment