Skip to content

Commit

Permalink
Fix issue with too many cookies in admin
Browse files Browse the repository at this point in the history
Port MC-19247 for adminhtml in order to not use jQuery.localStorage plugin
Move translation directory definition to base theme
Add deprecation notice to block and view files
  • Loading branch information
ihor-sviziev committed Aug 4, 2020
1 parent d3adb7a commit 72567f6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 64 deletions.
1 change: 0 additions & 1 deletion app/code/Magento/Backend/view/adminhtml/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
<argument name="bugreport_url" xsi:type="string">https://github.com/magento/magento2/issues</argument>
</arguments>
</block>

</container>
</container>
</referenceContainer>
Expand Down
3 changes: 1 addition & 2 deletions app/code/Magento/Backend/view/adminhtml/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
var config = {
map: {
'*': {
'mediaUploader': 'Magento_Backend/js/media-uploader',
'mage/translate': 'Magento_Backend/js/translate'
'mediaUploader': 'Magento_Backend/js/media-uploader'
}
}
};
4 changes: 4 additions & 0 deletions app/code/Magento/Translation/Block/Js.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
*
* @api
* @since 100.0.2
* @deprecated logic was refactored in order to not use localstorage at all.
*
* You can see details in app/code/Magento/Translation/view/base/web/js/mage-translation-dictionary.js
* These block and view file were left in order to keep backward compatibility
*/
class Js extends Template
{
Expand Down
15 changes: 15 additions & 0 deletions app/code/Magento/Translation/view/base/requirejs-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

var config = {
map: {
'*': {
mageTranslationDictionary: 'Magento_Translation/js/mage-translation-dictionary'
}
},
deps: [
'mageTranslationDictionary'
]
};
61 changes: 4 additions & 57 deletions app/code/Magento/Translation/view/base/templates/translate.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,8 @@
/**
* @var \Magento\Translation\Block\Js $block
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
* @deprecated logic was refactored in order to not use localstorage at all.
*
* You can see details in app/code/Magento/Translation/view/base/web/js/mage-translation-dictionary.js
* These block and view file were left in order to keep backward compatibility
*/
?>
<!--
For frontend area dictionary file is inserted into html head in Magento/Translation/view/base/templates/dictionary.phtml
Same translation mechanism should be introduced for admin area in 2.4 version.
-->
<?php
if ($block->dictionaryEnabled()) {
$version = $block->getTranslationFileVersion();
$escapedVersion = $block->escapeJs($version);
$dictionaryFileName = /* @noEscape */ Magento\Translation\Model\Js\Config::DICTIONARY_FILE_NAME;

$scriptString = <<<script
require.config({
deps: [
'jquery',
'mage/translate',
'jquery/jquery-storageapi'
],
callback: function ($) {
'use strict';
var dependencies = [],
versionObj;
$.initNamespaceStorage('mage-translation-storage');
$.initNamespaceStorage('mage-translation-file-version');
versionObj = $.localStorage.get('mage-translation-file-version');
if (versionObj.version !== '{$escapedVersion}') {
dependencies.push(
'text!{$dictionaryFileName}'
);
}
require.config({
deps: dependencies,
callback: function (string) {
if (typeof string === 'string') {
$.mage.translate.add(JSON.parse(string));
$.localStorage.set('mage-translation-storage', string);
$.localStorage.set(
'mage-translation-file-version',
{
version: '{$escapedVersion}'
}
);
} else {
$.mage.translate.add($.localStorage.get('mage-translation-storage'));
}
}
});
}
});
script;
echo /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ var config = {
'*': {
editTrigger: 'mage/edit-trigger',
addClass: 'Magento_Translation/js/add-class',
'Magento_Translation/add-class': 'Magento_Translation/js/add-class',
mageTranslationDictionary: 'Magento_Translation/js/mage-translation-dictionary'
'Magento_Translation/add-class': 'Magento_Translation/js/add-class'
}
},
deps: [
'mage/translate-inline',
'mageTranslationDictionary'
'mage/translate-inline'
]
};

0 comments on commit 72567f6

Please sign in to comment.