|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright © Wirecard Brasil. All rights reserved. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Bruno Elisei <[email protected]> |
|
6
|
|
|
* See COPYING.txt for license details. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Moip\Magento2\Block\Adminhtml\System\Config; |
|
10
|
|
|
|
|
11
|
|
|
use Magento\Framework\App\ObjectManager; |
|
|
|
|
|
|
12
|
|
|
use Magento\Framework\View\Helper\SecureHtmlRenderer; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class PaymentGroup - Fieldset renderer for moip. |
|
16
|
|
|
*/ |
|
17
|
|
|
class PaymentGroup extends \Magento\Config\Block\System\Config\Form\Fieldset |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var \Magento\Config\Model\Config |
|
|
|
|
|
|
21
|
|
|
*/ |
|
22
|
|
|
protected $_backendConfig; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var SecureHtmlRenderer |
|
26
|
|
|
*/ |
|
27
|
|
|
private $secureRenderer; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param \Magento\Backend\Block\Context $context |
|
31
|
|
|
* @param \Magento\Backend\Model\Auth\Session $authSession |
|
32
|
|
|
* @param \Magento\Framework\View\Helper\Js $jsHelper |
|
33
|
|
|
* @param \Magento\Config\Model\Config $backendConfig |
|
34
|
|
|
* @param array $data |
|
35
|
|
|
* @param SecureHtmlRenderer|null $secureRenderer |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct( |
|
38
|
|
|
\Magento\Backend\Block\Context $context, |
|
|
|
|
|
|
39
|
|
|
\Magento\Backend\Model\Auth\Session $authSession, |
|
|
|
|
|
|
40
|
|
|
\Magento\Framework\View\Helper\Js $jsHelper, |
|
|
|
|
|
|
41
|
|
|
\Magento\Config\Model\Config $backendConfig, |
|
42
|
|
|
SecureHtmlRenderer $secureRenderer, |
|
43
|
|
|
array $data = [] |
|
44
|
|
|
) { |
|
45
|
|
|
$this->_backendConfig = $backendConfig; |
|
46
|
|
|
$secureRenderer = $secureRenderer ?? ObjectManager::getInstance()->get(SecureHtmlRenderer::class); |
|
47
|
|
|
parent::__construct($context, $authSession, $jsHelper, $data, $secureRenderer); |
|
48
|
|
|
$this->secureRenderer = $secureRenderer; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Add custom css class. |
|
53
|
|
|
* |
|
54
|
|
|
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element |
|
|
|
|
|
|
55
|
|
|
* |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function _getFrontendClass($element) |
|
59
|
|
|
{ |
|
60
|
|
|
$enabledString = $this->_isPaymentEnabled($element) ? ' enabled' : ''; |
|
61
|
|
|
|
|
62
|
|
|
return parent::_getFrontendClass($element).' with-button'.$enabledString; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Check whether current payment method is enabled. |
|
67
|
|
|
* |
|
68
|
|
|
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element |
|
69
|
|
|
* |
|
70
|
|
|
* @return bool |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function _isPaymentEnabled($element) |
|
73
|
|
|
{ |
|
74
|
|
|
$groupConfig = $element->getGroup(); |
|
75
|
|
|
$activityPaths = isset($groupConfig['activity_path']) ? $groupConfig['activity_path'] : []; |
|
76
|
|
|
|
|
77
|
|
|
if (!is_array($activityPaths)) { |
|
78
|
|
|
$activityPaths = [$activityPaths]; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$isPaymentEnabled = false; |
|
82
|
|
|
foreach ($activityPaths as $activityPath) { |
|
83
|
|
|
$isPaymentEnabled = $isPaymentEnabled |
|
84
|
|
|
|| (bool) (string) $this->_backendConfig->getConfigDataValue($activityPath); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return $isPaymentEnabled; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Return header title part of html for payment solution. |
|
92
|
|
|
* |
|
93
|
|
|
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element |
|
94
|
|
|
* |
|
95
|
|
|
* @return string |
|
96
|
|
|
* @SuppressWarnings(PHPMD.NPathComplexity) |
|
97
|
|
|
*/ |
|
98
|
|
|
protected function _getHeaderTitleHtml($element) |
|
99
|
|
|
{ |
|
100
|
|
|
$html = '<div class="config-heading" >'; |
|
101
|
|
|
|
|
102
|
|
|
$groupConfig = $element->getGroup(); |
|
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
$htmlId = $element->getHtmlId(); |
|
105
|
|
|
$html .= '<div class="button-container"><button type="button"'. |
|
106
|
|
|
' class="button action-configure'. |
|
107
|
|
|
'" id="'.$htmlId.'-head" >'. |
|
108
|
|
|
'<span class="state-closed">'.__( |
|
|
|
|
|
|
109
|
|
|
'Configure' |
|
110
|
|
|
).'</span><span class="state-opened">'.__( |
|
111
|
|
|
'Close' |
|
112
|
|
|
).'</span></button>'; |
|
113
|
|
|
|
|
114
|
|
|
$html .= /* @noEscape */ $this->secureRenderer->renderEventListenerAsTag( |
|
115
|
|
|
'onclick', |
|
116
|
|
|
"moipToggleSolution.call(this, '".$htmlId."', '".$this->getUrl('adminhtml/*/state'). |
|
117
|
|
|
"');event.preventDefault();", |
|
118
|
|
|
'button#'.$htmlId.'-head' |
|
119
|
|
|
); |
|
120
|
|
|
$html .= '</div>'; |
|
121
|
|
|
$html .= '<div class="heading"><strong>'.$element->getLegend().'</strong>'; |
|
122
|
|
|
|
|
123
|
|
|
if ($element->getComment()) { |
|
124
|
|
|
$html .= '<span class="heading-intro">'.$element->getComment().'</span>'; |
|
125
|
|
|
} |
|
126
|
|
|
$html .= '<div class="config-alt"></div>'; |
|
127
|
|
|
$html .= '</div></div>'; |
|
128
|
|
|
|
|
129
|
|
|
return $html; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Return header comment part of html for payment solution. |
|
134
|
|
|
* |
|
135
|
|
|
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element |
|
136
|
|
|
* |
|
137
|
|
|
* @return string |
|
138
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
139
|
|
|
*/ |
|
140
|
|
|
protected function _getHeaderCommentHtml($element) |
|
141
|
|
|
{ |
|
142
|
|
|
return ''; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Get collapsed state on-load. |
|
147
|
|
|
* |
|
148
|
|
|
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element |
|
149
|
|
|
* |
|
150
|
|
|
* @return false |
|
151
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
152
|
|
|
*/ |
|
153
|
|
|
protected function _isCollapseState($element) |
|
154
|
|
|
{ |
|
155
|
|
|
return false; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Return extra Js. |
|
160
|
|
|
* |
|
161
|
|
|
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element |
|
162
|
|
|
* |
|
163
|
|
|
* @return string |
|
164
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
165
|
|
|
*/ |
|
166
|
|
|
protected function _getExtraJs($element) |
|
167
|
|
|
{ |
|
168
|
|
|
$script = "require(['jquery', 'prototype'], function(jQuery){ |
|
169
|
|
|
window.moipToggleSolution = function (id, url) { |
|
170
|
|
|
var doScroll = false; |
|
171
|
|
|
Fieldset.toggleCollapse(id, url); |
|
172
|
|
|
if ($(this).hasClassName(\"open\")) { |
|
173
|
|
|
\$$(\".with-button button.button\").each(function(anotherButton) { |
|
174
|
|
|
if (anotherButton != this && $(anotherButton).hasClassName(\"open\")) { |
|
175
|
|
|
$(anotherButton).click(); |
|
176
|
|
|
doScroll = true; |
|
177
|
|
|
} |
|
178
|
|
|
}.bind(this)); |
|
179
|
|
|
} |
|
180
|
|
|
if (doScroll) { |
|
181
|
|
|
var pos = Element.cumulativeOffset($(this)); |
|
182
|
|
|
window.scrollTo(pos[0], pos[1] - 45); |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
});"; |
|
186
|
|
|
|
|
187
|
|
|
return $this->_jsHelper->getScript($script); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths