diff --git a/lib/Drupal/config_translation/Controller/ConfigTranslationController.php b/lib/Drupal/config_translation/Controller/ConfigTranslationController.php index 1627b58..35fef56 100644 --- a/lib/Drupal/config_translation/Controller/ConfigTranslationController.php +++ b/lib/Drupal/config_translation/Controller/ConfigTranslationController.php @@ -163,7 +163,8 @@ class ConfigTranslationController implements ControllerInterface { // Enter context for the translation target language requested and generate // form with translation data in that language. config_translation_enter_context($language); - return drupal_get_form(new ConfigTranslationManageForm(), $group, $language, $base_config); + $locale_storage = \Drupal::service('locale.storage'); + return drupal_get_form(new ConfigTranslationManageForm($locale_storage), $group, $language, $base_config); } /** diff --git a/lib/Drupal/config_translation/Form/ConfigTranslationManageForm.php b/lib/Drupal/config_translation/Form/ConfigTranslationManageForm.php index 58d879e..2cf1994 100644 --- a/lib/Drupal/config_translation/Form/ConfigTranslationManageForm.php +++ b/lib/Drupal/config_translation/Form/ConfigTranslationManageForm.php @@ -11,6 +11,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Config\Config; use Drupal\config_translation\ConfigMapperInterface; use Drupal\Core\Config\Schema\Element; +use Drupal\locale\StringStorageInterface; /** * Provides a form for manage configuration translation. @@ -46,6 +47,22 @@ class ConfigTranslationManageForm implements FormInterface { protected $base_config = array(); /** + * String translation storage object. + * + * @var \Drupal\locale\StringStorageInterface + */ + protected $localeStorage; + + /** + * Creates manage form object with string translation storage. + * + * @param StringStorageInterface $locale_storage + */ + public function __construct(StringStorageInterface $locale_storage) { + $this->localeStorage = $locale_storage; + } + + /** * {@inheritdoc}. */ public function getFormID() { @@ -95,7 +112,7 @@ class ConfigTranslationManageForm implements FormInterface { // Set config values based on form submission and original values. $base_config = config($name); $translation_config = config('locale.config.' . $this->language->langcode . '.' . $name); - $locations = locale_storage()->getLocations(array('type' => 'configuration', 'name' => $name)); + $locations = $this->localeStorage->getLocations(array('type' => 'configuration', 'name' => $name)); $this->setConfig($this->language, $base_config, $translation_config, $form_values[$id], !empty($locations)); @@ -248,16 +265,16 @@ class ConfigTranslationManageForm implements FormInterface { // If the config file being translated was originally shipped, we should // update the locale translation storage. The string should already be // there, but we make sure to check. - if ($shipped_config && $source_string = locale_storage()->findString(array('source' => $base_config->get($key)))) { + if ($shipped_config && $source_string = $this->localeStorage->findString(array('source' => $base_config->get($key)))) { // Get the translation for this original source string from locale. $conditions = array( 'lid' => $source_string->lid, 'language' => $language->langcode, ); - $translations = locale_storage()->getTranslations($conditions + array('translated' => TRUE)); + $translations = $this->localeStorage->getTranslations($conditions + array('translated' => TRUE)); // If we got a translation, take that, otherwise create a new one. - $translation = reset($translations) ?: locale_storage()->createTranslation($conditions); + $translation = reset($translations) ?: $this->localeStorage->createTranslation($conditions); // If we have a new translation or different from what is stored in // locale before, save this as an updated customize translation. diff --git a/lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php b/lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php index 6c42482..be89e62 100644 --- a/lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php +++ b/lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php @@ -10,6 +10,7 @@ namespace Drupal\config_translation\Tests; use Drupal\Core\Config\FileStorage; use Drupal\simpletest\WebTestBase; use Drupal\Core\Language\Language; +use Drupal\locale\StringStorageInterface; /** * Functional tests for the Language list configuration forms. @@ -30,6 +31,13 @@ class ConfigTranslationUITest extends WebTestBase { */ protected $langcodes = array('fr', 'ta'); + /** + * String translation storage object. + * + * @var \Drupal\locale\StringStorageInterface + */ + protected $localeStorage; + public static function getInfo() { return array( 'name' => 'Configuration Translation', @@ -56,7 +64,7 @@ class ConfigTranslationUITest extends WebTestBase { $language = new Language(array('langcode' => $langcode)); language_save($language); } - + $this->localeStorage = $this->container->get('locale.storage'); } /** @@ -420,12 +428,12 @@ class ConfigTranslationUITest extends WebTestBase { * Returns translation if exists, FALSE otherwise. */ protected function getTranslation($config_name, $key, $langcode) { - $settings_locations = locale_storage()->getLocations(array('type' => 'configuration', 'name' => $config_name)); + $settings_locations = $this->localeStorage->getLocations(array('type' => 'configuration', 'name' => $config_name)); $this->assertTrue(!empty($settings_locations), format_string('Configuration locations found for %config_name.', array('%config_name' => $config_name))); if (!empty($settings_locations)) { $source = $this->container->get('config.factory')->get($config_name)->get($key); - $source_string = locale_storage()->findString(array('source' => $source, 'type' => 'configuration')); + $source_string = $this->localeStorage->findString(array('source' => $source, 'type' => 'configuration')); $this->assertTrue(!empty($source_string), format_string('Found string for %config_name.%key.', array('%config_name' => $config_name, '%key' => $key))); if (!empty($source_string)) { @@ -433,7 +441,7 @@ class ConfigTranslationUITest extends WebTestBase { 'lid' => $source_string->lid, 'language' => $langcode, ); - $translations = locale_storage()->getTranslations($conditions + array('translated' => TRUE)); + $translations = $this->localeStorage->getTranslations($conditions + array('translated' => TRUE)); return reset($translations); } }