|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / dev2.destoffenstraat.com / app / code / WeSupply / Toolbox / Block / System / Config / |
Filename | /home/dev2.destoffenstraat.com/app/code/WeSupply/Toolbox/Block/System/Config/AccessKey.php |
Size | 2.71 kb |
Permission | rwxrwxrwx |
Owner | root : root |
Create time | 17-Aug-2025 10:26 |
Last modified | 17-May-2021 07:16 |
Last accessed | 22-Aug-2025 19:39 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
namespace WeSupply\Toolbox\Block\System\Config;
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Exception\LocalizedException;
use WeSupply\Toolbox\Helper\Data as Helper;
class AccessKey extends Field
{
/**
* @var Helper
*/
protected $helper;
/**
* @var \Magento\Framework\App\RequestInterface
*/
protected $request;
/**
* AccessKey constructor.
* @param Context $context
* @param Helper $helper
* @param array $data
*/
public function __construct(
Context $context,
Helper $helper,
array $data = []
)
{
$this->helper = $helper;
$this->request = $context->getRequest();
parent::__construct($context, $data);
}
/**
* @return mixed
*/
public function getButtonHtml()
{
try {
$button = $this->getLayout()->createBlock(
'Magento\Backend\Block\Widget\Button'
)->setData(
[
'id' => 'generate_button',
'label' => __('Regenerate')
]
);
return $button->toHtml();
} catch (LocalizedException $e) {
}
}
/**
* Return ajax url for collect button
*
* @return string
*/
public function getAjaxUrl()
{
return $this->getUrl('wesupply/system_config/generate');
}
/**
* @return bool
*/
public function isVisible()
{
if (!$this->helper->getGuid() || !$this->helper->getGuidByScope()) {
// it was never saved
return true;
}
if (!$this->request->getParam('store') && !$this->request->getParam('website')) {
return true;
}
if ($this->helper->getGuid() != $this->helper->getGuidByScope()) {
return true;
}
return false;
}
/**
* @param AbstractElement $element
* @return string
* @throws LocalizedException
*/
protected function _getElementHtml(AbstractElement $element)
{
$element->setData('readonly', true);
return $element->getElementHtml() . $this->getTemplateHtml('copy') . $this->getTemplateHtml('generate');
}
/**
* @param $type
* @return mixed
* @throws LocalizedException
*/
protected function getTemplateHtml($type)
{
$content = $this->getLayout()->createBlock(
'Magento\Backend\Block\Template'
)->setTemplate(
'WeSupply_Toolbox::system/config/' . $type . '_access_key.phtml'
);
return $content->toHtml();
}
}
namespace WeSupply\Toolbox\Block\System\Config;
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Exception\LocalizedException;
use WeSupply\Toolbox\Helper\Data as Helper;
class AccessKey extends Field
{
/**
* @var Helper
*/
protected $helper;
/**
* @var \Magento\Framework\App\RequestInterface
*/
protected $request;
/**
* AccessKey constructor.
* @param Context $context
* @param Helper $helper
* @param array $data
*/
public function __construct(
Context $context,
Helper $helper,
array $data = []
)
{
$this->helper = $helper;
$this->request = $context->getRequest();
parent::__construct($context, $data);
}
/**
* @return mixed
*/
public function getButtonHtml()
{
try {
$button = $this->getLayout()->createBlock(
'Magento\Backend\Block\Widget\Button'
)->setData(
[
'id' => 'generate_button',
'label' => __('Regenerate')
]
);
return $button->toHtml();
} catch (LocalizedException $e) {
}
}
/**
* Return ajax url for collect button
*
* @return string
*/
public function getAjaxUrl()
{
return $this->getUrl('wesupply/system_config/generate');
}
/**
* @return bool
*/
public function isVisible()
{
if (!$this->helper->getGuid() || !$this->helper->getGuidByScope()) {
// it was never saved
return true;
}
if (!$this->request->getParam('store') && !$this->request->getParam('website')) {
return true;
}
if ($this->helper->getGuid() != $this->helper->getGuidByScope()) {
return true;
}
return false;
}
/**
* @param AbstractElement $element
* @return string
* @throws LocalizedException
*/
protected function _getElementHtml(AbstractElement $element)
{
$element->setData('readonly', true);
return $element->getElementHtml() . $this->getTemplateHtml('copy') . $this->getTemplateHtml('generate');
}
/**
* @param $type
* @return mixed
* @throws LocalizedException
*/
protected function getTemplateHtml($type)
{
$content = $this->getLayout()->createBlock(
'Magento\Backend\Block\Template'
)->setTemplate(
'WeSupply_Toolbox::system/config/' . $type . '_access_key.phtml'
);
return $content->toHtml();
}
}