Edit.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Variable\Block\System\Variable;
  7. /**
  8. * Custom Variable Edit Container
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Edit extends \Magento\Backend\Block\Widget\Form\Container
  14. {
  15. /**
  16. * Core registry
  17. *
  18. * @var \Magento\Framework\Registry
  19. */
  20. protected $_coreRegistry = null;
  21. /**
  22. * @param \Magento\Backend\Block\Widget\Context $context
  23. * @param \Magento\Framework\Registry $registry
  24. * @param array $data
  25. */
  26. public function __construct(
  27. \Magento\Backend\Block\Widget\Context $context,
  28. \Magento\Framework\Registry $registry,
  29. array $data = []
  30. ) {
  31. $this->_coreRegistry = $registry;
  32. parent::__construct($context, $data);
  33. }
  34. /**
  35. * Internal constructor
  36. *
  37. * @return void
  38. */
  39. protected function _construct()
  40. {
  41. $this->_objectId = 'variable_id';
  42. $this->_blockGroup = 'Magento_Variable';
  43. $this->_controller = 'system_variable';
  44. parent::_construct();
  45. }
  46. /**
  47. * Getter
  48. *
  49. * @return \Magento\Variable\Model\Variable
  50. */
  51. public function getVariable()
  52. {
  53. return $this->_coreRegistry->registry('current_variable');
  54. }
  55. /**
  56. * Prepare layout.
  57. * Adding save_and_continue button
  58. *
  59. * @return $this
  60. */
  61. protected function _preparelayout()
  62. {
  63. $this->addButton(
  64. 'save_and_edit',
  65. [
  66. 'label' => __('Save and Continue Edit'),
  67. 'class' => 'save',
  68. 'data_attribute' => [
  69. 'mage-init' => ['button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form']],
  70. ]
  71. ],
  72. 100
  73. );
  74. if (!$this->getVariable()->getId()) {
  75. $this->removeButton('delete');
  76. }
  77. return parent::_prepareLayout();
  78. }
  79. /**
  80. * Return form HTML
  81. *
  82. * @return string
  83. */
  84. public function getFormHtml()
  85. {
  86. return parent::getFormHtml();
  87. }
  88. /**
  89. * Return translated header text depending on creating/editing action
  90. *
  91. * @return \Magento\Framework\Phrase
  92. */
  93. public function getHeaderText()
  94. {
  95. if ($this->getVariable()->getId()) {
  96. return __('Custom Variable "%1"', $this->escapeHtml($this->getVariable()->getName()));
  97. } else {
  98. return __('New Custom Variable');
  99. }
  100. }
  101. /**
  102. * Return validation url for edit form
  103. *
  104. * @return string
  105. */
  106. public function getValidationUrl()
  107. {
  108. return $this->getUrl('adminhtml/*/validate', ['_current' => true]);
  109. }
  110. /**
  111. * Return save url for edit form
  112. *
  113. * @return string
  114. */
  115. public function getSaveUrl()
  116. {
  117. return $this->getUrl('adminhtml/*/save', ['_current' => true, 'back' => null]);
  118. }
  119. /**
  120. * Return save and continue url for edit form
  121. *
  122. * @return string
  123. */
  124. public function getSaveAndContinueUrl()
  125. {
  126. return $this->getUrl('adminhtml/*/save', ['_current' => true, 'back' => 'edit']);
  127. }
  128. }