-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApiKey.php
58 lines (52 loc) · 1.57 KB
/
ApiKey.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Copyright © Novatize. All rights reserved.
*/
namespace Auctane\Api\Block\System\Config;
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Config\Model\ResourceModel\Config\Data\Collection;
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
use Magento\Framework\Data\Form\Element\AbstractElement;
class ApiKey extends Field
{
/**
* @var CollectionFactory
*/
private $configCollectionFactory;
/**
* ApiKey constructor.
* @param Context $context
* @param CollectionFactory $configCollectionFactory
*/
public function __construct(
Context $context,
CollectionFactory $configCollectionFactory
) {
$this->configCollectionFactory = $configCollectionFactory;
parent::__construct($context);
}
/**
* @param AbstractElement $element
* @return string
*/
protected function _getElementHtml(AbstractElement $element)
{
$element->setData('value', $this->getApiKeyValue());
$element->setReadonly('readonly', 1);
return $element->getElementHtml();
}
/**
* @return string
*/
protected function getApiKeyValue()
{
// we use the config collection to bypass the config cache
/** @var Collection $collection */
$collection = $this->configCollectionFactory->create();
return $collection
->addFieldToFilter('path', 'shipstation_general/shipstation/ship_api_key')
->getFirstItem()
->getValue();
}
}