From fc34d7bf5afce2db5f6019dcb5c259e1178fb3dc Mon Sep 17 00:00:00 2001 From: Sergey Shvets Date: Fri, 10 Nov 2017 12:32:12 +0200 Subject: [PATCH] MAGETWO-72301: [Github] Static content deploy with multiple locales: js-translation.json files are the same #10673 --- .../Magento/Deploy/Service/DeployPackage.php | 30 +++--- .../Deploy/Service/DeployStaticContent.php | 1 + .../Translation/Model/Json/PreProcessor.php | 28 ++++-- .../Test/Unit/Model/Json/PreProcessorTest.php | 16 ++- .../Magento/Framework/TranslateTest.php | 47 ++++++--- .../design/Magento/theme/i18n/en_US.csv | 3 + .../Framework/Test/Unit/TranslateTest.php | 95 ++++++++++++------ lib/internal/Magento/Framework/Translate.php | 97 ++++++++++--------- 8 files changed, 208 insertions(+), 109 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Translation/Model/_files/Magento/design/Magento/theme/i18n/en_US.csv diff --git a/app/code/Magento/Deploy/Service/DeployPackage.php b/app/code/Magento/Deploy/Service/DeployPackage.php index 0522702cbdc2b..ec80387e96cc9 100644 --- a/app/code/Magento/Deploy/Service/DeployPackage.php +++ b/app/code/Magento/Deploy/Service/DeployPackage.php @@ -3,14 +3,18 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Deploy\Service; use Magento\Deploy\Package\Package; use Magento\Deploy\Package\PackageFile; +use Magento\Framework\App\ObjectManager; use Magento\Framework\App\State as AppState; use Magento\Framework\Locale\ResolverInterface as LocaleResolver; use Magento\Framework\View\Asset\ContentProcessorException; use Magento\Deploy\Console\InputValidator; +use Magento\Framework\View\Design\Theme\ListInterface; +use Magento\Framework\View\DesignInterface; use Psr\Log\LoggerInterface; /** @@ -91,15 +95,15 @@ public function __construct( * @param array $options * @param bool $skipLogging * @return bool true on success + * @throws \Exception */ public function deploy(Package $package, array $options, $skipLogging = false) { $result = $this->appState->emulateAreaCode( - $package->getArea() == Package::BASE_AREA ? 'global' : $package->getArea(), + $package->getArea() === Package::BASE_AREA ? 'global' : $package->getArea(), function () use ($package, $options, $skipLogging) { // emulate application locale needed for correct file path resolving $this->localeResolver->setLocale($package->getLocale()); - $this->deployEmulated($package, $options, $skipLogging); } ); @@ -111,7 +115,7 @@ function () use ($package, $options, $skipLogging) { * @param Package $package * @param array $options * @param bool $skipLogging - * @return int + * @return bool */ public function deployEmulated(Package $package, array $options, $skipLogging = false) { @@ -200,14 +204,14 @@ private function processFile(PackageFile $file, Package $package) private function checkIfCanCopy(PackageFile $file, Package $package, Package $parentPackage = null) { return $parentPackage - && $file->getOrigPackage() !== $package - && ( - $file->getArea() !== $package->getArea() - || $file->getTheme() !== $package->getTheme() - || $file->getLocale() !== $package->getLocale() - ) - && $file->getOrigPackage() == $parentPackage - && $this->deployStaticFile->readFile($file->getDeployedFileId(), $parentPackage->getPath()); + && $file->getOrigPackage() !== $package + && ( + $file->getArea() !== $package->getArea() + || $file->getTheme() !== $package->getTheme() + || $file->getLocale() !== $package->getLocale() + ) + && $file->getOrigPackage() === $parentPackage + && $this->deployStaticFile->readFile($file->getDeployedFileId(), $parentPackage->getPath()); } /** @@ -219,10 +223,10 @@ private function checkIfCanCopy(PackageFile $file, Package $package, Package $pa */ private function checkFileSkip($filePath, array $options) { - if ($filePath != '.') { + if ($filePath !== '.') { $ext = strtolower(pathinfo($filePath, PATHINFO_EXTENSION)); $basename = pathinfo($filePath, PATHINFO_BASENAME); - if ($ext == 'less' && strpos($basename, '_') === 0) { + if ($ext === 'less' && strpos($basename, '_') === 0) { return true; } $option = isset(InputValidator::$fileExtensionOptionMap[$ext]) diff --git a/app/code/Magento/Deploy/Service/DeployStaticContent.php b/app/code/Magento/Deploy/Service/DeployStaticContent.php index 66ec6e7418afd..72de645868e22 100644 --- a/app/code/Magento/Deploy/Service/DeployStaticContent.php +++ b/app/code/Magento/Deploy/Service/DeployStaticContent.php @@ -112,6 +112,7 @@ public function deploy(array $options) $deployRjsConfig = $this->objectManager->create(DeployRequireJsConfig::class, [ 'logger' => $this->logger ]); + /** @var DeployTranslationsDictionary $deployI18n */ $deployI18n = $this->objectManager->create(DeployTranslationsDictionary::class, [ 'logger' => $this->logger ]); diff --git a/app/code/Magento/Translation/Model/Json/PreProcessor.php b/app/code/Magento/Translation/Model/Json/PreProcessor.php index e29d8d768a0d6..1b2dd565d4ce5 100644 --- a/app/code/Magento/Translation/Model/Json/PreProcessor.php +++ b/app/code/Magento/Translation/Model/Json/PreProcessor.php @@ -3,15 +3,18 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Translation\Model\Json; +use Magento\Framework\App\AreaList; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\TranslateInterface; +use Magento\Framework\View\Asset\File\FallbackContext; +use Magento\Framework\View\Asset\PreProcessor\Chain; use Magento\Framework\View\Asset\PreProcessorInterface; +use Magento\Framework\View\DesignInterface; use Magento\Translation\Model\Js\Config; use Magento\Translation\Model\Js\DataProviderInterface; -use Magento\Framework\View\Asset\PreProcessor\Chain; -use Magento\Framework\View\Asset\File\FallbackContext; -use Magento\Framework\App\AreaList; -use Magento\Framework\TranslateInterface; /** * PreProcessor responsible for providing js translation dictionary @@ -41,23 +44,30 @@ class PreProcessor implements PreProcessorInterface * @var TranslateInterface */ protected $translate; + /** + * @var DesignInterface + */ + private $viewDesign; /** * @param Config $config * @param DataProviderInterface $dataProvider * @param AreaList $areaList * @param TranslateInterface $translate + * @param DesignInterface|null $viewDesign */ public function __construct( Config $config, DataProviderInterface $dataProvider, AreaList $areaList, - TranslateInterface $translate + TranslateInterface $translate, + DesignInterface $viewDesign = null ) { $this->config = $config; $this->dataProvider = $dataProvider; $this->areaList = $areaList; $this->translate = $translate; + $this->viewDesign = $viewDesign ?: ObjectManager::getInstance()->get(DesignInterface::class); } /** @@ -65,6 +75,7 @@ public function __construct( * * @param Chain $chain * @return void + * @throws \Exception */ public function process(Chain $chain) { @@ -77,7 +88,12 @@ public function process(Chain $chain) if ($context instanceof FallbackContext) { $themePath = $context->getThemePath(); $areaCode = $context->getAreaCode(); - $this->translate->setLocale($context->getLocale()); + + $this->viewDesign->setDesignTheme($themePath, $areaCode); + + $this->translate + ->setLocale($context->getLocale()) + ->loadData($areaCode); } $area = $this->areaList->getArea($areaCode); diff --git a/app/code/Magento/Translation/Test/Unit/Model/Json/PreProcessorTest.php b/app/code/Magento/Translation/Test/Unit/Model/Json/PreProcessorTest.php index eb53c5b442cdd..c99993e425da4 100644 --- a/app/code/Magento/Translation/Test/Unit/Model/Json/PreProcessorTest.php +++ b/app/code/Magento/Translation/Test/Unit/Model/Json/PreProcessorTest.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Translation\Test\Unit\Model\Json; use Magento\Translation\Model\Js\Config; @@ -41,7 +42,15 @@ protected function setUp() $this->configMock = $this->createMock(\Magento\Translation\Model\Js\Config::class); $this->dataProviderMock = $this->createMock(\Magento\Translation\Model\Js\DataProvider::class); $this->areaListMock = $this->createMock(\Magento\Framework\App\AreaList::class); - $this->translateMock = $this->getMockForAbstractClass(\Magento\Framework\TranslateInterface::class); + $this->translateMock = $this->getMockBuilder(\Magento\Framework\Translate::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->translateMock + ->expects($this->once()) + ->method('setLocale') + ->willReturn($this->translateMock); + $this->model = new PreProcessor( $this->configMock, $this->dataProviderMock, @@ -97,6 +106,11 @@ public function testGetData() ->method('setContentType') ->with('json'); + $this->translateMock + ->expects($this->once()) + ->method('loadData') + ->willReturn($this->translateMock); + $this->model->process($chain); } } diff --git a/dev/tests/integration/testsuite/Magento/Framework/TranslateTest.php b/dev/tests/integration/testsuite/Magento/Framework/TranslateTest.php index 73e6fba8276c7..b11b881847a57 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/TranslateTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/TranslateTest.php @@ -3,40 +3,43 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Framework; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\Helper\CacheCleaner; +use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_MockObject_MockObject; /** * @magentoAppIsolation enabled * @magentoCache all disabled * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class TranslateTest extends \PHPUnit\Framework\TestCase +class TranslateTest extends TestCase { /** @var \Magento\Framework\Translate */ private $translate; protected function setUp() { - /** @var \Magento\Framework\View\FileSystem $viewFileSystem */ + /** @var \Magento\Framework\View\FileSystem | PHPUnit_Framework_MockObject_MockObject $viewFileSystem */ $viewFileSystem = $this->createPartialMock( \Magento\Framework\View\FileSystem::class, - ['getLocaleFileName', 'getDesignTheme'] + ['getLocaleFileName'] ); $viewFileSystem->expects($this->any()) ->method('getLocaleFileName') ->will( - $this->returnValue(dirname(__DIR__) . '/Theme/Model/_files/design/frontend/Test/default/i18n/en_US.csv') + $this->returnValue( + dirname(__DIR__) . '/Translation/Model/_files/Magento/design/Magento/theme/i18n/en_US.csv' + ) ); - /** @var \Magento\Framework\View\Design\ThemeInterface $theme */ + /** @var \Magento\Framework\View\Design\ThemeInterface | PHPUnit_Framework_MockObject_MockObject $theme */ $theme = $this->createMock(\Magento\Framework\View\Design\ThemeInterface::class); - $theme->expects($this->any())->method('getId')->will($this->returnValue(10)); - - $viewFileSystem->expects($this->any())->method('getDesignTheme')->will($this->returnValue($theme)); + $theme->expects($this->any())->method('getThemePath')->will($this->returnValue('Magento/luma')); /** @var \Magento\TestFramework\ObjectManager $objectManager */ $objectManager = Bootstrap::getObjectManager(); @@ -55,7 +58,7 @@ protected function setUp() dirname(__DIR__) . '/Translation/Model/_files/Magento/Catalog/i18n' ); - /** @var \Magento\Theme\Model\View\Design $designModel */ + /** @var \Magento\Theme\Model\View\Design | \PHPUnit_Framework_MockObject_MockObject $designModel */ $designModel = $this->getMockBuilder(\Magento\Theme\Model\View\Design::class) ->setMethods(['getDesignTheme']) ->setConstructorArgs( @@ -96,6 +99,9 @@ public function testLoadData() /** * @magentoCache all disabled * @dataProvider translateDataProvider + * @param string $inputText + * @param string $expectedTranslation + * @throws Exception\LocalizedException */ public function testTranslate($inputText, $expectedTranslation) { @@ -111,9 +117,26 @@ public function translateDataProvider() { return [ ['', ''], - ['Text with different translation on different modules', 'Text translation that was last loaded'], - ['text_with_no_translation', 'text_with_no_translation'], - ['Design value to translate', 'Design translated value'] + [ + 'Theme phrase will be translated', + 'Theme phrase is translated', + ], + [ + 'Phrase in Magento_Store module that doesn\'t need translation', + 'Phrase in Magento_Store module that doesn\'t need translation', + ], + [ + 'Phrase in Magento_Catalog module that doesn\'t need translation', + 'Phrase in Magento_Catalog module that doesn\'t need translation', + ], + [ + 'Magento_Store module phrase will be override by theme translation', + 'Magento_Store module phrase is override by theme translation', + ], + [ + 'Magento_Catalog module phrase will be override by theme translation', + 'Magento_Catalog module phrase is override by theme translation', + ], ]; } } diff --git a/dev/tests/integration/testsuite/Magento/Translation/Model/_files/Magento/design/Magento/theme/i18n/en_US.csv b/dev/tests/integration/testsuite/Magento/Translation/Model/_files/Magento/design/Magento/theme/i18n/en_US.csv new file mode 100644 index 0000000000000..f34ef38890738 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Translation/Model/_files/Magento/design/Magento/theme/i18n/en_US.csv @@ -0,0 +1,3 @@ +"Theme phrase will be translated","Theme phrase is translated" +"Magento_Catalog module phrase will be override by theme translation","Magento_Catalog module phrase is override by theme translation" +"Magento_Store module phrase will be override by theme translation","Magento_Store module phrase is override by theme translation" diff --git a/lib/internal/Magento/Framework/Test/Unit/TranslateTest.php b/lib/internal/Magento/Framework/Test/Unit/TranslateTest.php index 5c689adc6743c..cca8d564d3199 100644 --- a/lib/internal/Magento/Framework/Test/Unit/TranslateTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/TranslateTest.php @@ -121,27 +121,60 @@ protected function setUp() * @param string $area * @param bool $forceReload * @param array $cachedData + * @dataProvider dataProviderLoadDataCachedTranslation + */ + public function testLoadDataCachedTranslation($area, $forceReload, $cachedData) + { + $this->expectsSetConfig('Magento/luma'); + + $this->cache->expects($this->once()) + ->method('load') + ->will($this->returnValue(json_encode($cachedData))); + + $this->appState->expects($this->exactly($area ? 0 : 1)) + ->method('getAreaCode') + ->will($this->returnValue('frontend')); + + $this->translate->loadData($area, $forceReload); + $this->assertEquals($cachedData, $this->translate->getData()); + } + + public function dataProviderLoadDataCachedTranslation() + { + $cachedData = ['cached 1' => 'translated 1', 'cached 2' => 'translated 2']; + return [ + ['adminhtml', false, $cachedData], + ['frontend', false, $cachedData], + [null, false, $cachedData], + ]; + } + + /** + * @param string $area + * @param bool $forceReload * @dataProvider dataProviderForTestLoadData * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function testLoadData($area, $forceReload, $cachedData) + public function testLoadData($area, $forceReload) { - $this->expectsSetConfig('themeId'); + $this->expectsSetConfig('Magento/luma'); + + $this->appState->expects($this->exactly($area ? 0 : 1)) + ->method('getAreaCode') + ->will($this->returnValue('frontend')); $this->cache->expects($this->exactly($forceReload ? 0 : 1)) ->method('load') - ->will($this->returnValue(json_encode($cachedData))); - - if (!$forceReload && $cachedData !== false) { - $this->translate->loadData($area, $forceReload); - $this->assertEquals($cachedData, $this->translate->getData()); - return; - } + ->will($this->returnValue(false)); $this->directory->expects($this->any())->method('isExist')->will($this->returnValue(true)); // _loadModuleTranslation() - $this->moduleList->expects($this->once())->method('getNames')->will($this->returnValue(['name'])); + $modules = ['some_module', 'other_module', 'another_module', 'current_module']; + $this->request->expects($this->any()) + ->method('getControllerModule') + ->willReturn('current_module'); + $this->moduleList->expects($this->once())->method('getNames')->will($this->returnValue($modules)); $moduleData = [ 'module original' => 'module translated', 'module theme' => 'module-theme original translated', @@ -167,11 +200,6 @@ public function testLoadData($area, $forceReload, $cachedData) ) ); - // _loadThemeTranslation() - $this->viewFileSystem->expects($this->any()) - ->method('getLocaleFileName') - ->will($this->returnValue('/theme.csv')); - // _loadPackTranslation $packData = [ 'pack original' => 'pack translated', @@ -180,6 +208,11 @@ public function testLoadData($area, $forceReload, $cachedData) ]; $this->packDictionary->expects($this->once())->method('getDictionary')->will($this->returnValue($packData)); + // _loadThemeTranslation() + $this->viewFileSystem->expects($this->any()) + ->method('getLocaleFileName') + ->will($this->returnValue('/theme.csv')); + // _loadDbTranslation() $dbData = [ 'db original' => 'db translated', @@ -187,9 +220,7 @@ public function testLoadData($area, $forceReload, $cachedData) ]; $this->resource->expects($this->any())->method('getTranslationArray')->will($this->returnValue($dbData)); - if (!$forceReload) { - $this->cache->expects($this->exactly(1))->method('save'); - } + $this->cache->expects($this->exactly($forceReload ? 0 : 1))->method('save'); $this->translate->loadData($area, $forceReload); @@ -207,20 +238,13 @@ public function testLoadData($area, $forceReload, $cachedData) public function dataProviderForTestLoadData() { - $cachedData = ['cached 1' => 'translated 1', 'cached 2' => 'translated 2']; return [ - ['adminhtml', true, false], - ['adminhtml', true, $cachedData], - ['adminhtml', false, $cachedData], - ['adminhtml', false, false], - ['frontend', true, false], - ['frontend', true, $cachedData], - ['frontend', false, $cachedData], - ['frontend', false, false], - [null, true, false], - [null, true, $cachedData], - [null, false, $cachedData], - [null, false, false] + ['adminhtml', true], + ['adminhtml', false], + ['frontend', true], + ['frontend', false], + [null, true], + [null, false] ]; } @@ -309,7 +333,14 @@ protected function expectsSetConfig($themeId, $localeCode = 'en_US') ] ) ); - $designTheme = new \Magento\Framework\DataObject(['id' => $themeId]); + $designTheme = $this->getMockBuilder(\Magento\Theme\Model\Theme::class) + ->disableOriginalConstructor() + ->getMock(); + + $designTheme->expects($this->once()) + ->method('getThemePath') + ->willReturn($themeId); + $this->viewDesign->expects($this->any())->method('getDesignTheme')->will($this->returnValue($designTheme)); } } diff --git a/lib/internal/Magento/Framework/Translate.php b/lib/internal/Magento/Framework/Translate.php index 9ce3925925e1e..3dc74175c8770 100644 --- a/lib/internal/Magento/Framework/Translate.php +++ b/lib/internal/Magento/Framework/Translate.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Framework; use Magento\Framework\App\Filesystem\DirectoryList; @@ -15,6 +16,12 @@ */ class Translate implements \Magento\Framework\TranslateInterface { + const CONFIG_AREA_KEY = 'area'; + const CONFIG_LOCALE_KEY = 'locale'; + const CONFIG_SCOPE_KEY = 'scope'; + const CONFIG_THEME_KEY = 'theme'; + const CONFIG_MODULE_KEY = 'module'; + /** * Locale code * @@ -158,6 +165,14 @@ public function __construct( $this->directory = $filesystem->getDirectoryRead(DirectoryList::ROOT); $this->_csvParser = $csvParser; $this->packDictionary = $packDictionary; + + $this->_config = [ + self::CONFIG_AREA_KEY => null, + self::CONFIG_LOCALE_KEY => null, + self::CONFIG_SCOPE_KEY => null, + self::CONFIG_THEME_KEY => null, + self::CONFIG_MODULE_KEY => null + ]; } /** @@ -166,20 +181,26 @@ public function __construct( * @param string|null $area * @param bool $forceReload * @return $this + * @throws Exception\LocalizedException */ public function loadData($area = null, $forceReload = false) { + $this->_data = []; + if ($area === null) { + $area = $this->_appState->getAreaCode(); + } $this->setConfig( - ['area' => isset($area) ? $area : $this->_appState->getAreaCode()] + [ + self::CONFIG_AREA_KEY => $area, + ] ); if (!$forceReload) { - $this->_data = $this->_loadCache(); - if ($this->_data !== false) { + if (false !== $data = $this->_loadCache()) { + $this->_data = $data; return $this; } } - $this->_data = []; $this->_loadModuleTranslation(); $this->_loadPackTranslation(); @@ -202,17 +223,17 @@ public function loadData($area = null, $forceReload = false) protected function setConfig($config) { $this->_config = $config; - if (!isset($this->_config['locale'])) { - $this->_config['locale'] = $this->getLocale(); + if (!isset($this->_config[self::CONFIG_LOCALE_KEY])) { + $this->_config[self::CONFIG_LOCALE_KEY] = $this->getLocale(); } - if (!isset($this->_config['scope'])) { - $this->_config['scope'] = $this->getScope(); + if (!isset($this->_config[self::CONFIG_SCOPE_KEY])) { + $this->_config[self::CONFIG_SCOPE_KEY] = $this->getScope(); } - if (!isset($this->_config['theme'])) { - $this->_config['theme'] = $this->_viewDesign->getDesignTheme()->getId(); + if (!isset($this->_config[self::CONFIG_THEME_KEY])) { + $this->_config[self::CONFIG_THEME_KEY] = $this->_viewDesign->getDesignTheme()->getThemePath(); } - if (!isset($this->_config['module'])) { - $this->_config['module'] = $this->getControllerModuleName(); + if (!isset($this->_config[self::CONFIG_MODULE_KEY])) { + $this->_config[self::CONFIG_MODULE_KEY] = $this->getControllerModuleName(); } return $this; } @@ -224,7 +245,7 @@ protected function setConfig($config) */ protected function getScope() { - $scope = ($this->getConfig('area') == 'adminhtml') ? 'admin' : null; + $scope = ($this->getConfig(self::CONFIG_AREA_KEY) === 'adminhtml') ? 'admin' : null; return $this->_scopeResolver->getScope($scope)->getCode(); } @@ -295,7 +316,7 @@ protected function _addData($data) } $key = str_replace('""', '"', $key); - $value = str_replace('""', '"', $value); + $value = str_replace('""', '"', $value); $this->_data[$key] = $value; } @@ -309,10 +330,6 @@ protected function _addData($data) */ protected function _loadThemeTranslation() { - if (!$this->_config['theme']) { - return $this; - } - $file = $this->_getThemeTranslationFile($this->getLocale()); if ($file) { $this->_addData($this->_getFileData($file)); @@ -339,7 +356,7 @@ protected function _loadPackTranslation() protected function _loadDbTranslation() { $data = $this->_translateResource->getTranslationArray(null, $this->getLocale()); - $this->_addData(array_map("htmlspecialchars_decode", $data)); + $this->_addData(array_map('htmlspecialchars_decode', $data)); return $this; } @@ -367,7 +384,7 @@ protected function _getThemeTranslationFile($locale) { return $this->_viewFileSystem->getLocaleFileName( 'i18n' . '/' . $locale . '.csv', - ['area' => $this->getConfig('area')] + $this->_config ); } @@ -422,8 +439,7 @@ public function getLocale() public function setLocale($locale) { $this->_localeCode = $locale; - $this->_config['locale'] = $locale; - $this->getCacheId(true); + $this->_config[self::CONFIG_LOCALE_KEY] = $locale; return $this; } @@ -434,11 +450,11 @@ public function setLocale($locale) */ public function getTheme() { - $theme = $this->request->getParam('theme'); + $theme = $this->request->getParam(self::CONFIG_THEME_KEY); if (empty($theme)) { - return 'theme' . $this->getConfig('theme'); + return self::CONFIG_THEME_KEY . $this->getConfig(self::CONFIG_THEME_KEY); } - return 'theme' . $theme['theme_title']; + return self::CONFIG_THEME_KEY . $theme['theme_title']; } /** @@ -446,28 +462,19 @@ public function getTheme() * * @param bool $forceReload * @return string + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function getCacheId($forceReload = false) { - if ($this->_cacheId === null || $forceReload) { - $this->_cacheId = \Magento\Framework\App\Cache\Type\Translate::TYPE_IDENTIFIER; - if (isset($this->_config['locale'])) { - $this->_cacheId .= '_' . $this->_config['locale']; - } - if (isset($this->_config['area'])) { - $this->_cacheId .= '_' . $this->_config['area']; - } - if (isset($this->_config['scope'])) { - $this->_cacheId .= '_' . $this->_config['scope']; - } - if (isset($this->_config['theme'])) { - $this->_cacheId .= '_' . $this->_config['theme']; - } - if (isset($this->_config['module'])) { - $this->_cacheId .= '_' . $this->_config['module']; - } - } - return $this->_cacheId; + $_cacheId = \Magento\Framework\App\Cache\Type\Translate::TYPE_IDENTIFIER; + $_cacheId .= '_' . $this->_config[self::CONFIG_LOCALE_KEY]; + $_cacheId .= '_' . $this->_config[self::CONFIG_AREA_KEY]; + $_cacheId .= '_' . $this->_config[self::CONFIG_SCOPE_KEY]; + $_cacheId .= '_' . $this->_config[self::CONFIG_THEME_KEY]; + $_cacheId .= '_' . $this->_config[self::CONFIG_MODULE_KEY]; + + $this->_cacheId = $_cacheId; + return $_cacheId; } /** @@ -491,7 +498,7 @@ protected function _loadCache() */ protected function _saveCache() { - $this->_cache->save($this->getSerializer()->serialize($this->getData()), $this->getCacheId(true), [], false); + $this->_cache->save($this->getSerializer()->serialize($this->getData()), $this->getCacheId(), [], false); return $this; }