Skip to content
Snippets Groups Projects
Unverified Commit 6b6facdc authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3422977 by secretsayan, traviscarden, nexusnovaz, joachim, smustgrave,...

Issue #3422977 by secretsayan, traviscarden, nexusnovaz, joachim, smustgrave, xjm, catch: Rename locale batch operation callbacks to match the API methods they call
parent de542f58
No related branches found
No related tags found
No related merge requests found
...@@ -571,7 +571,7 @@ function locale_config_batch_update_components(array $options, array $langcodes ...@@ -571,7 +571,7 @@ function locale_config_batch_update_components(array $options, array $langcodes
* @return array * @return array
* The batch definition. * The batch definition.
* *
* @see locale_config_batch_refresh_name() * @see locale_config_batch_update_config_translations()
*/ */
function locale_config_batch_build(array $names, array $langcodes, array $options = [], bool $update_default_config_langcodes = FALSE) { function locale_config_batch_build(array $names, array $langcodes, array $options = [], bool $update_default_config_langcodes = FALSE) {
$options += ['finish_feedback' => TRUE]; $options += ['finish_feedback' => TRUE];
...@@ -582,7 +582,7 @@ function locale_config_batch_build(array $names, array $langcodes, array $option ...@@ -582,7 +582,7 @@ function locale_config_batch_build(array $names, array $langcodes, array $option
->setErrorMessage(t('Error updating configuration translations')); ->setErrorMessage(t('Error updating configuration translations'));
if ($update_default_config_langcodes && \Drupal::languageManager()->getDefaultLanguage()->getId() !== 'en') { if ($update_default_config_langcodes && \Drupal::languageManager()->getDefaultLanguage()->getId() !== 'en') {
$batch_builder->addOperation('locale_config_batch_set_config_langcodes'); $batch_builder->addOperation('locale_config_batch_update_default_config_langcodes');
} }
// Chunking the array of names into batches of 20 for better performance. // Chunking the array of names into batches of 20 for better performance.
...@@ -593,7 +593,7 @@ function locale_config_batch_build(array $names, array $langcodes, array $option ...@@ -593,7 +593,7 @@ function locale_config_batch_build(array $names, array $langcodes, array $option
// it is very expensive to initialize the \Drupal::config() object on each // it is very expensive to initialize the \Drupal::config() object on each
// request. We batch a small number of configuration object upgrades // request. We batch a small number of configuration object upgrades
// together to improve the overall performance of the process. // together to improve the overall performance of the process.
$batch_builder->addOperation('locale_config_batch_refresh_name', [$chunk, $langcodes]); $batch_builder->addOperation('locale_config_batch_update_config_translations', [$chunk, $langcodes]);
} }
if (!empty($options['finish_feedback'])) { if (!empty($options['finish_feedback'])) {
...@@ -610,12 +610,30 @@ function locale_config_batch_build(array $names, array $langcodes, array $option ...@@ -610,12 +610,30 @@ function locale_config_batch_build(array $names, array $langcodes, array $option
* @param array|\ArrayAccess $context * @param array|\ArrayAccess $context
* The batch context. * The batch context.
*/ */
function locale_config_batch_set_config_langcodes(&$context) { function locale_config_batch_update_default_config_langcodes(&$context): void {
\Drupal::service('locale.config_manager')->updateDefaultConfigLangcodes(); \Drupal::service('locale.config_manager')->updateDefaultConfigLangcodes();
$context['finished'] = 1; $context['finished'] = 1;
$context['message'] = t('Updated default configuration to %langcode', ['%langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId()]); $context['message'] = t('Updated default configuration to %langcode', ['%langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId()]);
} }
/**
* Implements callback_batch_operation().
*
* Updates default configuration when new modules or themes are installed.
*
* @param array|\ArrayAccess $context
* The batch context.
*
* @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. Use
* locale_config_batch_update_default_config_langcodes(&$context) instead.
*
* @see https://www.drupal.org/node/3475054
*/
function locale_config_batch_set_config_langcodes(&$context): void {
@trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. Use locale_config_batch_update_default_config_langcodes() instead. See https://www.drupal.org/node/3475054', E_USER_DEPRECATED);
locale_config_batch_update_default_config_langcodes($context);
}
/** /**
* Implements callback_batch_operation(). * Implements callback_batch_operation().
* *
...@@ -630,7 +648,7 @@ function locale_config_batch_set_config_langcodes(&$context) { ...@@ -630,7 +648,7 @@ function locale_config_batch_set_config_langcodes(&$context) {
* *
* @see locale_config_batch_build() * @see locale_config_batch_build()
*/ */
function locale_config_batch_refresh_name(array $names, array $langcodes, &$context) { function locale_config_batch_update_config_translations(array $names, array $langcodes, &$context): void {
if (!isset($context['results']['stats']['config'])) { if (!isset($context['results']['stats']['config'])) {
$context['results']['stats']['config'] = 0; $context['results']['stats']['config'] = 0;
} }
...@@ -643,6 +661,28 @@ function locale_config_batch_refresh_name(array $names, array $langcodes, &$cont ...@@ -643,6 +661,28 @@ function locale_config_batch_refresh_name(array $names, array $langcodes, &$cont
$context['finished'] = 1; $context['finished'] = 1;
} }
/**
* Implements callback_batch_operation().
*
* Performs configuration translation refresh.
*
* @param array $names
* An array of names of configuration objects to update.
* @param array $langcodes
* (optional) Array of language codes to update. Defaults to all languages.
* @param array|\ArrayAccess $context
* Contains a list of files imported.
*
* @deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. Use
* locale_config_batch_update_config_translations($names, $langcodes, $context) instead.
*
* @see https://www.drupal.org/node/3475054
*/
function locale_config_batch_refresh_name(array $names, array $langcodes, &$context): void {
@trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. Use locale_config_batch_update_config_translations() instead. See https://www.drupal.org/node/3475054', E_USER_DEPRECATED);
locale_config_batch_update_config_translations($names, $langcodes, $context);
}
/** /**
* Implements callback_batch_finished(). * Implements callback_batch_finished().
* *
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\locale\Unit;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
/**
* Tests locale.bulk.inc.
*
* @group locale
*/
class LocaleBulkDeprecationTest extends UnitTestCase {
protected function setUp(): void {
parent::setUp();
$container = new ContainerBuilder();
$container->set('locale.config_manager', $this->createMock('Drupal\locale\LocaleConfigManager'));
$language_manager = $this->createMock('Drupal\Core\Language\LanguageManagerInterface');
$language_manager->expects($this->any())
->method('getDefaultLanguage')
->willReturn($this->createMock('Drupal\Core\Language\LanguageInterface'));
$container->set('language_manager', $language_manager);
\Drupal::setContainer($container);
include_once DRUPAL_ROOT . '/core/modules/locale/locale.bulk.inc';
}
/**
* Tests the deprecation of locale_config_batch_refresh_name().
*
* @group legacy
*
* @see locale_config_batch_refresh_name()
*/
public function testDeprecatedLocaleConfigBatchRefreshName(): void {
$this->expectDeprecation('locale_config_batch_refresh_name() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. Use locale_config_batch_update_config_translations() instead. See https://www.drupal.org/node/3475054');
$names = ['English', 'German'];
$langcodes = ['en', 'de'];
locale_config_batch_refresh_name($names, $langcodes, $context);
}
/**
* Tests the deprecation of locale_config_batch_set_config_langcodes().
*
* @group legacy
*
* @see locale_config_batch_set_config_langcodes()
*/
public function testDeprecatedLocaleConfigBatchSetConfigLangcodes(): void {
$this->expectDeprecation('locale_config_batch_set_config_langcodes() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. Use locale_config_batch_update_default_config_langcodes() instead. See https://www.drupal.org/node/3475054');
$context = [];
locale_config_batch_set_config_langcodes($context);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment