Edit.php 3.0 KB

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