Info.php 5.9 KB

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