Edit.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Integration edit container.
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Integration\Block\Adminhtml\Integration;
  9. use Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info;
  10. use Magento\Integration\Controller\Adminhtml\Integration;
  11. /**
  12. * @api
  13. * @since 100.0.2
  14. */
  15. class Edit extends \Magento\Backend\Block\Widget\Form\Container
  16. {
  17. /**
  18. * Core registry
  19. *
  20. * @var \Magento\Framework\Registry
  21. */
  22. protected $_registry = null;
  23. /**
  24. * @var \Magento\Integration\Helper\Data
  25. */
  26. protected $_integrationHelper;
  27. /**
  28. * Initialize dependencies.
  29. *
  30. * @param \Magento\Backend\Block\Widget\Context $context
  31. * @param \Magento\Framework\Registry $registry
  32. * @param \Magento\Integration\Helper\Data $integrationHelper
  33. * @param array $data
  34. */
  35. public function __construct(
  36. \Magento\Backend\Block\Widget\Context $context,
  37. \Magento\Framework\Registry $registry,
  38. \Magento\Integration\Helper\Data $integrationHelper,
  39. array $data = []
  40. ) {
  41. $this->_registry = $registry;
  42. $this->_integrationHelper = $integrationHelper;
  43. parent::__construct($context, $data);
  44. }
  45. /**
  46. * Initialize Integration edit page
  47. *
  48. * @return void
  49. */
  50. protected function _construct()
  51. {
  52. $this->_controller = 'adminhtml_integration';
  53. $this->_blockGroup = 'Magento_Integration';
  54. parent::_construct();
  55. $this->buttonList->remove('reset');
  56. $this->buttonList->remove('delete');
  57. if ($this->_integrationHelper->isConfigType(
  58. $this->_registry->registry(Integration::REGISTRY_KEY_CURRENT_INTEGRATION)
  59. )
  60. ) {
  61. $this->buttonList->remove('save');
  62. }
  63. if ($this->_isNewIntegration()) {
  64. $this->removeButton(
  65. 'save'
  66. )->addButton(
  67. 'save',
  68. [
  69. 'id' => 'save-split-button',
  70. 'label' => __('Save'),
  71. 'class_name' => \Magento\Backend\Block\Widget\Button\SplitButton::class,
  72. 'button_class' => '',
  73. 'data_attribute' => [
  74. 'mage-init' => ['button' => ['event' => 'save', 'target' => '#edit_form']],
  75. ],
  76. 'options' => [
  77. 'save_activate' => [
  78. 'id' => 'activate',
  79. 'label' => __('Save & Activate'),
  80. 'data_attribute' => [
  81. 'mage-init' => [
  82. 'button' => ['event' => 'saveAndActivate', 'target' => '#edit_form'],
  83. 'integration' => ['gridUrl' => $this->getUrl('*/*/')],
  84. ],
  85. ],
  86. ],
  87. ]
  88. ]
  89. );
  90. }
  91. }
  92. /**
  93. * Get header text for edit page.
  94. *
  95. * @return \Magento\Framework\Phrase
  96. */
  97. public function getHeaderText()
  98. {
  99. if ($this->_isNewIntegration()) {
  100. return __('New Integration');
  101. } else {
  102. return __(
  103. "Edit Integration '%1'",
  104. $this->escapeHtml(
  105. $this->_registry->registry(Integration::REGISTRY_KEY_CURRENT_INTEGRATION)[Info::DATA_NAME]
  106. )
  107. );
  108. }
  109. }
  110. /**
  111. * {@inheritdoc}
  112. */
  113. public function getFormActionUrl()
  114. {
  115. return $this->getUrl('*/*/save');
  116. }
  117. /**
  118. * Determine whether we create new integration or editing an existing one.
  119. *
  120. * @return bool
  121. */
  122. protected function _isNewIntegration()
  123. {
  124. return !isset($this->_registry->registry(Integration::REGISTRY_KEY_CURRENT_INTEGRATION)[Info::DATA_ID]);
  125. }
  126. }