From 4821bf79803258b77748b8325bf231b93107124e Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 3 Feb 2021 16:02:39 +0000 Subject: [PATCH] Issue #3128389 by clayfreeman, jungle, cliddell, john.oltman, acbramley, larowlan: [backport] LocaleTranslation is not serializable --- core/modules/locale/src/LocaleTranslation.php | 3 ++ .../src/Kernel/LocaleTranslationTest.php | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 core/modules/locale/tests/src/Kernel/LocaleTranslationTest.php diff --git a/core/modules/locale/src/LocaleTranslation.php b/core/modules/locale/src/LocaleTranslation.php index 94125e91d85..e9b693894e5 100644 --- a/core/modules/locale/src/LocaleTranslation.php +++ b/core/modules/locale/src/LocaleTranslation.php @@ -4,6 +4,7 @@ namespace Drupal\locale; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\DestructableInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageManagerInterface; @@ -19,6 +20,8 @@ use Symfony\Component\HttpFoundation\RequestStack; */ class LocaleTranslation implements TranslatorInterface, DestructableInterface { + use DependencySerializationTrait; + /** * Storage for strings. * diff --git a/core/modules/locale/tests/src/Kernel/LocaleTranslationTest.php b/core/modules/locale/tests/src/Kernel/LocaleTranslationTest.php new file mode 100644 index 00000000000..ef925bc2ff0 --- /dev/null +++ b/core/modules/locale/tests/src/Kernel/LocaleTranslationTest.php @@ -0,0 +1,34 @@ +container->get('string_translator.locale.lookup'); + $this->assertInstanceOf(LocaleTranslation::class, $translation); + + // Prove that serialization and deserialization works without errors. + $this->assertNotNull($translation); + $unserialized = unserialize(serialize($translation)); + $this->assertInstanceOf(LocaleTranslation::class, $unserialized); + } + +}