diff --git a/Block/Adminhtml/Render/Obscured.php b/Block/Adminhtml/Render/Obscured.php new file mode 100644 index 00000000..4450fa94 --- /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/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", 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/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 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') + }) +})