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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Integration\Block\Adminhtml\Integration\Edit\Tab;
use Magento\Integration\Controller\Adminhtml\Integration;
use Magento\Integration\Model\Integration as IntegrationModel;
/**
* Main Integration info edit form
*
* @api
* @since 100.0.2
*/
class Info extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface
{
/**#@+
* Form elements names.
*/
const HTML_ID_PREFIX = 'integration_properties_';
const DATA_ID = 'integration_id';
const DATA_NAME = 'name';
const DATA_EMAIL = 'email';
const DATA_ENDPOINT = 'endpoint';
const DATA_IDENTITY_LINK_URL = 'identity_link_url';
const DATA_SETUP_TYPE = 'setup_type';
const DATA_CONSUMER_ID = 'consumer_id';
const DATA_CONSUMER_PASSWORD = 'current_password';
/**#@-*/
/**
* Set form id prefix, declare fields for integration info
*
* @return $this
*/
protected function _prepareForm()
{
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix(self::HTML_ID_PREFIX);
$integrationData = $this->_coreRegistry->registry(Integration::REGISTRY_KEY_CURRENT_INTEGRATION);
$this->_addGeneralFieldset($form, $integrationData);
$this->_addDetailsFieldset($form, $integrationData);
$form->setValues($integrationData);
$this->setForm($form);
return $this;
}
/**
* Prepare label for tab
*
* @return \Magento\Framework\Phrase
*/
public function getTabLabel()
{
return __('Integration Info');
}
/**
* Prepare title for tab
*
* @return string
*/
public function getTabTitle()
{
return $this->getTabLabel();
}
/**
* Returns status flag about this tab can be shown or not
*
* @return true
*/
public function canShowTab()
{
return true;
}
/**
* Returns status flag about this tab hidden or not
*
* @return true
*/
public function isHidden()
{
return false;
}
/**
* Add fieldset with general integration information.
*
* @param \Magento\Framework\Data\Form $form
* @param array $integrationData
* @return void
*/
protected function _addGeneralFieldset($form, $integrationData)
{
$fieldset = $form->addFieldset('base_fieldset', ['legend' => __('General')]);
$disabled = false;
if (isset($integrationData[self::DATA_ID])) {
$fieldset->addField(self::DATA_ID, 'hidden', ['name' => 'id']);
if ($integrationData[self::DATA_SETUP_TYPE] == IntegrationModel::TYPE_CONFIG) {
$disabled = true;
}
}
$fieldset->addField(
self::DATA_NAME,
'text',
[
'label' => __('Name'),
'name' => self::DATA_NAME,
'required' => true,
'disabled' => $disabled,
'maxlength' => '255'
]
);
$fieldset->addField(
self::DATA_EMAIL,
'text',
[
'label' => __('Email'),
'name' => self::DATA_EMAIL,
'disabled' => $disabled,
'class' => 'validate-email',
'maxlength' => '254'
]
);
$fieldset->addField(
self::DATA_ENDPOINT,
'text',
[
'label' => __('Callback URL'),
'name' => self::DATA_ENDPOINT,
'disabled' => $disabled,
// @codingStandardsIgnoreStart
'note' => __(
'Enter URL where Oauth credentials can be sent when using Oauth for token exchange. We strongly recommend using https://.'
)
// @codingStandardsIgnoreEnd
]
);
$fieldset->addField(
self::DATA_IDENTITY_LINK_URL,
'text',
[
'label' => __('Identity link URL'),
'name' => self::DATA_IDENTITY_LINK_URL,
'disabled' => $disabled,
'note' => __(
'URL to redirect user to link their 3rd party account with this Magento integration credentials.'
)
]
);
$currentUserVerificationFieldset = $form->addFieldset(
'current_user_verification_fieldset',
['legend' => __('Current User Identity Verification')]
);
$currentUserVerificationFieldset->addField(
self::DATA_CONSUMER_PASSWORD,
'password',
[
'name' => self::DATA_CONSUMER_PASSWORD,
'label' => __('Your Password'),
'id' => self::DATA_CONSUMER_PASSWORD,
'title' => __('Your Password'),
'class' => 'input-text validate-current-password required-entry',
'required' => true
]
);
}
/**
* Add fieldset with integration details. This fieldset is available for existing integrations only.
*
* @param \Magento\Framework\Data\Form $form
* @param array $integrationData
* @return void
*/
protected function _addDetailsFieldset($form, $integrationData)
{
if (isset($integrationData[self::DATA_ID])) {
$fieldset = $form->addFieldset('details_fieldset', ['legend' => __('Integration Details')]);
/** @var \Magento\Integration\Block\Adminhtml\Integration\Tokens $tokensBlock */
$tokensBlock = $this->getChildBlock('integration_tokens');
foreach ($tokensBlock->getFormFields() as $field) {
$fieldset->addField($field['name'], $field['type'], $field['metadata']);
}
}
}
}