-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from paynl/feature/PLUG-3327
PLUG-3327 - Password Field
- Loading branch information
Showing
7 changed files
with
145 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Paynl\Payment\Block\Adminhtml\Render; | ||
|
||
use Magento\Backend\Block\Template\Context; | ||
use Magento\Config\Block\System\Config\Form\Field; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
|
||
class Obscured extends Field | ||
{ | ||
protected $configPath; | ||
protected $_template = 'Paynl_Payment::system/config/obscured.phtml'; | ||
|
||
/** | ||
* | ||
* @var Magento\Framework\App\Config\ScopeConfigInterface | ||
*/ | ||
protected $scopeConfig; | ||
|
||
/** | ||
* | ||
* @var Magento\Framework\App\RequestInterface | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param Context $context | ||
* @param ScopeConfigInterface $scopeConfig | ||
* @param RequestInterface $request | ||
*/ | ||
public function __construct(Context $context, ScopeConfigInterface $scopeConfig, RequestInterface $request) | ||
{ | ||
$this->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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<span class="obscuredField"> | ||
<input type="text" name="<?php echo $this->getNamePrefix() ?>" value="<?php echo $this->getDecryptedValue(); ?>" /> | ||
<span class="obscuredDisplay"></span> | ||
</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require([ | ||
'jquery', | ||
'Magento_Ui/js/modal/alert' | ||
], function ($, alert) { | ||
$('.obscuredDisplay').click(function () { | ||
$(this).parent().find('input').toggleClass('display') | ||
}) | ||
}) |