Issue #3422915 by magaki, karanpagare, joachim, alexpott, Keshav Patel, smustgrave, Aguillet: Deprecate Drupal\locale\Locale and its one method
parent
7cfb8bbd48
commit
dc9a4c537e
|
@ -6,12 +6,11 @@
|
|||
*/
|
||||
|
||||
use Drupal\Core\Batch\BatchBuilder;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Core\File\Exception\FileException;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\file\FileInterface;
|
||||
use Drupal\locale\Gettext;
|
||||
use Drupal\locale\Locale;
|
||||
|
||||
/**
|
||||
* Prepare a batch to import all translations.
|
||||
|
@ -328,7 +327,8 @@ function locale_translate_batch_refresh(&$context) {
|
|||
}
|
||||
elseif ($name = array_shift($context['sandbox']['refresh']['names'])) {
|
||||
// Refresh all languages for one object at a time.
|
||||
$count = Locale::config()->updateConfigTranslations([$name], $context['sandbox']['refresh']['languages']);
|
||||
$count = \Drupal::service('locale.config_manager')
|
||||
->updateConfigTranslations([$name], $context['sandbox']['refresh']['languages']);
|
||||
$context['results']['stats']['config'] += $count;
|
||||
// Inherit finished information from the "parent" string lookup step so
|
||||
// visual display of status will make sense.
|
||||
|
@ -344,7 +344,8 @@ function locale_translate_batch_refresh(&$context) {
|
|||
// Clear cache and force refresh of JavaScript translations.
|
||||
_locale_refresh_translations($context['sandbox']['refresh']['languages'], $next);
|
||||
// Check whether we need to refresh configuration objects.
|
||||
if ($names = Locale::config()->getStringNames($next)) {
|
||||
if ($names = \Drupal::service('locale.config_manager')
|
||||
->getStringNames($next)) {
|
||||
$context['sandbox']['refresh']['names_finished'] = $context['finished'];
|
||||
$context['sandbox']['refresh']['names'] = $names;
|
||||
}
|
||||
|
@ -547,7 +548,7 @@ function locale_translate_delete_translation_files(array $projects = [], array $
|
|||
*/
|
||||
function locale_config_batch_update_components(array $options, array $langcodes = [], array $components = [], bool $update_default_config_langcodes = FALSE) {
|
||||
$langcodes = $langcodes ? $langcodes : array_keys(\Drupal::languageManager()->getLanguages());
|
||||
if ($langcodes && $names = Locale::config()->getComponentNames($components)) {
|
||||
if ($langcodes && $names = \Drupal::service('locale.config_manager')->getComponentNames($components)) {
|
||||
// If the component list is empty we need to ensure that all configuration
|
||||
// in the default collection is using the site's default langcode.
|
||||
return locale_config_batch_build($names, $langcodes, $options, $update_default_config_langcodes);
|
||||
|
@ -612,7 +613,7 @@ function locale_config_batch_build(array $names, array $langcodes, array $option
|
|||
* The batch context.
|
||||
*/
|
||||
function locale_config_batch_set_config_langcodes(&$context) {
|
||||
Locale::config()->updateDefaultConfigLangcodes();
|
||||
\Drupal::service('locale.config_manager')->updateDefaultConfigLangcodes();
|
||||
$context['finished'] = 1;
|
||||
$context['message'] = t('Updated default configuration to %langcode', ['%langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId()]);
|
||||
}
|
||||
|
@ -635,7 +636,8 @@ function locale_config_batch_refresh_name(array $names, array $langcodes, &$cont
|
|||
if (!isset($context['results']['stats']['config'])) {
|
||||
$context['results']['stats']['config'] = 0;
|
||||
}
|
||||
$context['results']['stats']['config'] += Locale::config()->updateConfigTranslations($names, $langcodes);
|
||||
$context['results']['stats']['config'] += \Drupal::service('locale.config_manager')
|
||||
->updateConfigTranslations($names, $langcodes);
|
||||
foreach ($names as $name) {
|
||||
$context['results']['names'][] = $name;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ use Drupal\Core\Routing\RouteMatchInterface;
|
|||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\language\ConfigurableLanguageInterface;
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use Drupal\locale\Locale;
|
||||
use Drupal\locale\LocaleEvent;
|
||||
use Drupal\locale\LocaleEvents;
|
||||
|
||||
|
@ -238,7 +237,7 @@ function locale_configurable_language_delete(ConfigurableLanguageInterface $lang
|
|||
locale_translate_delete_translation_files([], [$language->id()]);
|
||||
|
||||
// Remove translated configuration objects.
|
||||
Locale::config()->deleteLanguageTranslations($language->id());
|
||||
\Drupal::service('locale.config_manager')->deleteLanguageTranslations($language->id());
|
||||
|
||||
// Changing the language settings impacts the interface:
|
||||
_locale_invalidate_js($language->id());
|
||||
|
@ -367,7 +366,7 @@ function locale_cron() {
|
|||
* Updates default configuration when new modules or themes are installed.
|
||||
*/
|
||||
function locale_system_set_config_langcodes() {
|
||||
Locale::config()->updateDefaultConfigLangcodes();
|
||||
\Drupal::service('locale.config_manager')->updateDefaultConfigLangcodes();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1053,8 +1052,9 @@ function _locale_refresh_translations($langcodes, $lids = []) {
|
|||
* List of string identifiers that have been updated / created.
|
||||
*/
|
||||
function _locale_refresh_configuration(array $langcodes, array $lids) {
|
||||
if ($lids && $langcodes && $names = Locale::config()->getStringNames($lids)) {
|
||||
Locale::config()->updateConfigTranslations($names, $langcodes);
|
||||
$locale_config_manager = \Drupal::service('locale.config_manager');
|
||||
if ($lids && $langcodes && $names = $locale_config_manager->getStringNames($lids)) {
|
||||
$locale_config_manager->updateConfigTranslations($names, $langcodes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,15 @@
|
|||
|
||||
namespace Drupal\locale;
|
||||
|
||||
@trigger_error('The ' . __NAMESPACE__ . '\Locale is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3437110', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Static service container wrapper for locale.
|
||||
*
|
||||
* @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0.
|
||||
* There is no replacement.
|
||||
*
|
||||
* @see https://www.drupal.org/node/3437110
|
||||
*/
|
||||
class Locale {
|
||||
|
||||
|
@ -13,11 +20,16 @@ class Locale {
|
|||
* Use the locale config manager service for creating locale-wrapped typed
|
||||
* configuration objects.
|
||||
*
|
||||
* @see \Drupal\Core\TypedData\TypedDataManager::create()
|
||||
*
|
||||
* @return \Drupal\locale\LocaleConfigManager
|
||||
* The locale configuration manager.
|
||||
*
|
||||
* @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0.
|
||||
* Use \Drupal::service('locale.config_manager') instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/3437110
|
||||
*/
|
||||
public static function config() {
|
||||
@trigger_error(__METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal::service(\'locale.config_manager\') instead. See https://www.drupal.org/node/3437110', E_USER_DEPRECATED);
|
||||
return \Drupal::service('locale.config_manager');
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\locale\Functional;
|
||||
|
||||
use Drupal\locale\Locale;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests translation update's effects on configuration translations.
|
||||
|
@ -233,7 +232,7 @@ class LocaleConfigTranslationImportTest extends BrowserTestBase {
|
|||
$string = $locale_storage->findString(['source' => 'Locale can translate']);
|
||||
\Drupal::service('locale.storage')->delete($string);
|
||||
// Force a rebuild of config translations.
|
||||
$count = Locale::config()->updateConfigTranslations(['locale_test_translate.settings'], ['af']);
|
||||
$count = \Drupal::service('locale.config_manager')->updateConfigTranslations(['locale_test_translate.settings'], ['af']);
|
||||
$this->assertEquals(1, $count, 'Correct count of updated translations');
|
||||
|
||||
$override = \Drupal::languageManager()->getLanguageConfigOverride('af', 'locale_test_translate.settings');
|
||||
|
|
|
@ -4,11 +4,10 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\locale\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\locale\Locale;
|
||||
use Drupal\locale\StringInterface;
|
||||
use Drupal\locale\TranslationString;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests that shipped configuration translations are updated correctly.
|
||||
|
@ -69,8 +68,9 @@ class LocaleConfigSubscriberTest extends KernelTestBase {
|
|||
// @see locale_system_update()
|
||||
locale_system_set_config_langcodes();
|
||||
$langcodes = array_keys(\Drupal::languageManager()->getLanguages());
|
||||
$names = Locale::config()->getComponentNames();
|
||||
Locale::config()->updateConfigTranslations($names, $langcodes);
|
||||
$locale_config_manager = \Drupal::service('locale.config_manager');
|
||||
$names = $locale_config_manager->getComponentNames();
|
||||
$locale_config_manager->updateConfigTranslations($names, $langcodes);
|
||||
|
||||
$this->configFactory = $this->container->get('config.factory');
|
||||
$this->stringStorage = $this->container->get('locale.storage');
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\locale\Unit;
|
||||
|
||||
use Drupal\Core\DependencyInjection\Container;
|
||||
use Drupal\locale\Locale;
|
||||
use Drupal\locale\LocaleConfigManager;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\locale\Locale
|
||||
* @group Cache
|
||||
*/
|
||||
class LocaleTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Tests deprecation of config() method.
|
||||
*
|
||||
* @covers ::config
|
||||
* @group legacy
|
||||
*/
|
||||
public function testConfig() {
|
||||
$config_manager = $this->prophesize(LocaleConfigManager::class);
|
||||
$container = $this->prophesize(Container::class);
|
||||
$container->get('locale.config_manager')
|
||||
->willReturn($config_manager->reveal());
|
||||
\Drupal::setContainer($container->reveal());
|
||||
|
||||
$this->expectDeprecation('The Drupal\locale\Locale is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3437110');
|
||||
$this->expectDeprecation('Drupal\locale\Locale::config() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal::service(\'locale.config_manager\') instead. See https://www.drupal.org/node/3437110');
|
||||
|
||||
$this->assertInstanceOf(LocaleConfigManager::class, Locale::config());
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,6 @@ namespace Drupal\Tests\user\Kernel;
|
|||
use Drupal\Core\Test\AssertMailTrait;
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\locale\Locale;
|
||||
|
||||
/**
|
||||
* Tests _user_mail_notify() use of user.settings.notify.*.
|
||||
|
@ -131,8 +130,9 @@ class UserMailNotifyTest extends EntityKernelTestBase {
|
|||
|
||||
locale_system_set_config_langcodes();
|
||||
$langcodes = array_keys(\Drupal::languageManager()->getLanguages());
|
||||
$names = Locale::config()->getComponentNames();
|
||||
Locale::config()->updateConfigTranslations($names, $langcodes);
|
||||
$locale_config_manager = \Drupal::service('locale.config_manager');
|
||||
$names = $locale_config_manager->getComponentNames();
|
||||
$locale_config_manager->updateConfigTranslations($names, $langcodes);
|
||||
|
||||
$this->config('user.settings')->set('notify.password_reset', TRUE)->save();
|
||||
|
||||
|
|
Loading…
Reference in New Issue