Tokens.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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;
  7. use Magento\Integration\Controller\Adminhtml\Integration as IntegrationController;
  8. /**
  9. * Main Integration properties edit form
  10. *
  11. * @api
  12. * @SuppressWarnings(PHPMD.DepthOfInheritance)
  13. * @since 100.0.2
  14. */
  15. class Tokens extends \Magento\Backend\Block\Widget\Form\Generic
  16. {
  17. /**#@+
  18. * Form element name.
  19. */
  20. const DATA_TOKEN = 'token';
  21. const DATA_TOKEN_SECRET = 'token_secret';
  22. const DATA_CONSUMER_KEY = 'consumer_key';
  23. const DATA_CONSUMER_SECRET = 'consumer_secret';
  24. /**#@-*/
  25. /**
  26. * Set form id prefix, declare fields for integration consumer modal
  27. *
  28. * @return $this
  29. */
  30. protected function _prepareForm()
  31. {
  32. /** @var \Magento\Framework\Data\Form $form */
  33. $form = $this->_formFactory->create();
  34. $htmlIdPrefix = 'integration_token_';
  35. $form->setHtmlIdPrefix($htmlIdPrefix);
  36. $fieldset = $form->addFieldset(
  37. 'base_fieldset',
  38. ['legend' => __('Integration Tokens for Extensions'), 'class' => ' fieldset-wide']
  39. );
  40. foreach ($this->getFormFields() as $field) {
  41. $fieldset->addField($field['name'], $field['type'], $field['metadata']);
  42. }
  43. $integrationData = $this->_coreRegistry->registry(IntegrationController::REGISTRY_KEY_CURRENT_INTEGRATION);
  44. if ($integrationData) {
  45. $form->setValues($integrationData);
  46. }
  47. $this->setForm($form);
  48. return parent::_prepareForm();
  49. }
  50. /**
  51. * Return a list of form fields with oAuth credentials.
  52. *
  53. * @return array
  54. */
  55. public function getFormFields()
  56. {
  57. return [
  58. [
  59. 'name' => self::DATA_CONSUMER_KEY,
  60. 'type' => 'text',
  61. 'metadata' => [
  62. 'label' => __('Consumer Key'),
  63. 'name' => self::DATA_CONSUMER_KEY,
  64. 'readonly' => true,
  65. ],
  66. ],
  67. [
  68. 'name' => self::DATA_CONSUMER_SECRET,
  69. 'type' => 'text',
  70. 'metadata' => [
  71. 'label' => __('Consumer Secret'),
  72. 'name' => self::DATA_CONSUMER_SECRET,
  73. 'readonly' => true,
  74. ]
  75. ],
  76. [
  77. 'name' => self::DATA_TOKEN,
  78. 'type' => 'text',
  79. 'metadata' => ['label' => __('Access Token'), 'name' => self::DATA_TOKEN, 'readonly' => true]
  80. ],
  81. [
  82. 'name' => self::DATA_TOKEN_SECRET,
  83. 'type' => 'text',
  84. 'metadata' => [
  85. 'label' => __('Access Token Secret'),
  86. 'name' => self::DATA_TOKEN_SECRET,
  87. 'readonly' => true,
  88. ]
  89. ]
  90. ];
  91. }
  92. }