From 5a3358edc706ce9079a04421db19a96e70a4134a Mon Sep 17 00:00:00 2001 From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com> Date: Tue, 9 Apr 2024 11:41:28 +0200 Subject: [PATCH 1/4] PLUG-3327 - Password Field --- Block/Adminhtml/Render/Obscured.php | 94 +++++++++++++++++++ etc/adminhtml/system.xml | 7 +- view/adminhtml/layout/default.xml | 1 + .../templates/system/config/obscured.phtml | 4 + view/adminhtml/web/js/configtab.js | 8 ++ 5 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 Block/Adminhtml/Render/Obscured.php create mode 100644 view/adminhtml/templates/system/config/obscured.phtml create mode 100644 view/adminhtml/web/js/configtab.js diff --git a/Block/Adminhtml/Render/Obscured.php b/Block/Adminhtml/Render/Obscured.php new file mode 100644 index 00000000..77460e99 --- /dev/null +++ b/Block/Adminhtml/Render/Obscured.php @@ -0,0 +1,94 @@ +scopeConfig = $scopeConfig; + $this->request = $request; + parent::__construct($context); + } + + /** + * + * @param AbstractElement $element + * + * @return string + */ + protected function _getElementHtml(AbstractElement $element) // phpcs:ignore + + { + $this->configPath = $element->getData('field_config')['config_path']; + $this->setNamePrefix($element->getName()) + ->setHtmlId($element->getHtmlId()); + return $this->_toHtml(); + } + + /** + * + * @return string + */ + public function getValue() + { + $data = $this->getConfigData(); + if (isset($data[$this->configPath])) { + $data = $data[$this->configPath]; + } else { + $data = ''; + } + return $data; + } + + /** + * @return string + */ + public function getDecryptedValue() + { + $storeId = $this->request->getParam('store'); + $websiteId = $this->request->getParam('website'); + + $scope = 'default'; + $scopeId = 0; + + if ($storeId) { + $scope = 'stores'; + $scopeId = $storeId; + } + if ($websiteId) { + $scope = 'websites'; + $scopeId = $websiteId; + } + + $apiToken = trim((string) $this->scopeConfig->getValue($this->configPath, $scope, $scopeId)); + return $apiToken ?? $this->getValue(); + } +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 108a728b..1d0aa67b 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -27,13 +27,14 @@ payment/paynl/tokencode - + here.]]> - payment/paynl/apitoken_encrypted - Magento\Config\Model\Config\Backend\Encrypted + Paynl\Payment\Block\Adminhtml\Render\Obscured + payment/paynl/apitoken_encrypted + Magento\Config\Model\Config\Backend\Encrypted diff --git a/view/adminhtml/layout/default.xml b/view/adminhtml/layout/default.xml index e8577185..7e3341c3 100644 --- a/view/adminhtml/layout/default.xml +++ b/view/adminhtml/layout/default.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/view/adminhtml/templates/system/config/obscured.phtml b/view/adminhtml/templates/system/config/obscured.phtml new file mode 100644 index 00000000..3d0c3c5f --- /dev/null +++ b/view/adminhtml/templates/system/config/obscured.phtml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/view/adminhtml/web/js/configtab.js b/view/adminhtml/web/js/configtab.js new file mode 100644 index 00000000..614f490d --- /dev/null +++ b/view/adminhtml/web/js/configtab.js @@ -0,0 +1,8 @@ +require([ + 'jquery', + 'Magento_Ui/js/modal/alert' +], function ($, alert) { + $('.obscuredDisplay').click(function () { + $(this).parent().find('input').toggleClass('display') + }) +}) From 50812ac447d1b1031bb58b4c83f298316bfbcf52 Mon Sep 17 00:00:00 2001 From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:39:42 +0200 Subject: [PATCH 2/4] Update style --- view/adminhtml/web/css/configtab.css | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/view/adminhtml/web/css/configtab.css b/view/adminhtml/web/css/configtab.css index d50ba682..f2573609 100644 --- a/view/adminhtml/web/css/configtab.css +++ b/view/adminhtml/web/css/configtab.css @@ -85,3 +85,36 @@ float: left; margin-left: 10px; } + +.obscuredField { + position: relative; +} + +.obscuredField input{ + text-security: disc; + -webkit-text-security: disc; + -moz-text-security: disc; +} + +.obscuredField input.display{ + text-security: none; + -webkit-text-security: none; + -moz-text-security: none; +} + +.obscuredField .obscuredDisplay{ + position: absolute; + right: 10px; + top: 0; + cursor: pointer; +} + +.obscuredField .obscuredDisplay::before{ + content: '\e60f'; + -webkit-font-smoothing: antialiased; + font-family: 'Admin Icons'; + font-style: normal; + font-weight: normal; + line-height: 1; + speak: none; +} \ No newline at end of file From 25e05aa7e3e874d2d17d3404e3ea8c2a07181ba1 Mon Sep 17 00:00:00 2001 From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:41:30 +0200 Subject: [PATCH 3/4] Code Polish --- Block/Adminhtml/Render/Obscured.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Block/Adminhtml/Render/Obscured.php b/Block/Adminhtml/Render/Obscured.php index 77460e99..4450fa94 100644 --- a/Block/Adminhtml/Render/Obscured.php +++ b/Block/Adminhtml/Render/Obscured.php @@ -30,6 +30,7 @@ class Obscured extends Field * * @param Context $context * @param ScopeConfigInterface $scopeConfig + * @param RequestInterface $request */ public function __construct(Context $context, ScopeConfigInterface $scopeConfig, RequestInterface $request) { @@ -45,7 +46,6 @@ public function __construct(Context $context, ScopeConfigInterface $scopeConfig, * @return string */ protected function _getElementHtml(AbstractElement $element) // phpcs:ignore - { $this->configPath = $element->getData('field_config')['config_path']; $this->setNamePrefix($element->getName()) From 8723b9e11e745de30726c2b2358ff7137935649d Mon Sep 17 00:00:00 2001 From: woutse Date: Thu, 18 Apr 2024 12:29:23 +0200 Subject: [PATCH 4/4] Bumped version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8b6c7dd1..4235e4b4 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "paynl/magento2-plugin", "description": "PAY. Payment methods for Magento2", "type": "magento2-module", - "version": "3.11.4", + "version": "3.12.0", "require": { "magento/module-sales": "^102.0.0 || ^103.0.0", "magento/module-payment": "^100.3.0",