Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. namespace vendor nameModule nameBlockAdminhtmlBackgroundImageEdit;
  2.  
  3.  
  4. class Form extends MagentoBackendBlockWidgetFormGeneric
  5. {
  6. /**
  7. * Prepare form
  8. *
  9. * @return $this
  10. */
  11. public function _prepareForm()
  12. {
  13. /** @var MagentoFrameworkDataForm $form */
  14. $form = $this->_formFactory->create(
  15. [
  16. 'data' => [
  17. 'id' => 'edit_form',
  18. 'action' => $this->getData('action'),
  19. 'method' => 'post',
  20. 'enctype' => 'multipart/form-data'
  21. ]
  22. ]
  23. );
  24. $form->setUseContainer(true);
  25. $this->setForm($form);
  26. return parent::_prepareForm();
  27. }
  28. }
  29.  
  30. namespace FvendorNamemoduleNameBlockAdminhtmlBackgroundImage;
  31.  
  32.  
  33. class Edit extends MagentoBackendBlockWidgetFormContainer
  34. {
  35.  
  36. protected $_coreRegistry = null;
  37.  
  38.  
  39. public function __construct(
  40. MagentoBackendBlockWidgetContext $context,
  41. MagentoFrameworkRegistry $registry,
  42. array $data = []
  43. ) {
  44. $this->_coreRegistry = $registry;
  45. parent::__construct($context, $data);
  46. }
  47.  
  48.  
  49. protected function _construct()
  50. {
  51. $this->_objectId = 'backgroundimage_id';
  52. $this->_blockGroup = 'FME_BackgroundImage';
  53. $this->_controller = 'adminhtml_backgroundImage';
  54. parent::_construct();
  55.  
  56. if ($this->_isAllowedAction('FME_BackgroundImage::save')) {
  57. $this->buttonList->update('save', 'label', __('Save Image'));
  58. $this->buttonList->add(
  59. 'saveandcontinue',
  60. [
  61. 'label' => __('Save and Continue Edit'),
  62. 'class' => 'save',
  63. 'data_attribute' => [
  64. 'mage-init' => [
  65. 'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'],
  66. ],
  67. ]
  68. ],
  69. -100
  70. );
  71. } else {
  72. $this->buttonList->remove('save');
  73. }
  74.  
  75.  
  76. }
  77.  
  78. /**
  79. * Retrieve text for header element depending on loaded page
  80. *
  81. * @return string
  82. */
  83. public function getHeaderText()
  84. {
  85. if ($this->_coreRegistry->registry('backgroundimage')->getId()) {
  86. return __(
  87. "Edit BackgroundImage '%1'",
  88. $this->escapeHtml($this->_coreRegistry->registry('backgroundimage')->getTitle())
  89. );
  90. } else {
  91. return __('New BackgroundImage');
  92. }
  93. }
  94.  
  95. /**
  96. * Check permission for passed action
  97. *
  98. * @param string $resourceId
  99. * @return bool
  100. */
  101. public function _isAllowedAction($resourceId)
  102. {
  103. return $this->_authorization->isAllowed($resourceId);
  104. }
  105.  
  106. /**
  107. * Getter of url for "Save and Continue" button
  108. * tab_id will be replaced by desired by JS later
  109. *
  110. * @return string
  111. */
  112. public function _getSaveAndContinueUrl()
  113. {
  114. return $this->getUrl(
  115. 'backgroundimage/*/save',
  116. ['_current' => true, 'back' => 'edit', 'active_tab' => '{{tab_id}}']
  117. );
  118. }
  119.  
  120. public function getFormActionUrl()
  121. {
  122. if ($this->hasFormActionUrl()) {
  123. return $this->getData('form_action_url');
  124. }
  125.  
  126. return $this->getUrl('*/*/save');
  127. }
  128.  
  129. /**
  130. * Prepare layout
  131. *
  132. * @return MagentoFrameworkViewElementAbstractBlock
  133. */
  134. public function _prepareLayout()
  135. {
  136. $this->_formScripts[] = "
  137. function toggleEditor() {
  138. if (tinyMCE.getInstanceById('page_content') == null) {
  139. tinyMCE.execCommand('mceAddControl', false, 'page_content');
  140. } else {
  141. tinyMCE.execCommand('mceRemoveControl', false, 'page_content');
  142. }
  143. };
  144. ";
  145. return parent::_prepareLayout();
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement