Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. <?php
  2.  
  3. namespace LearningHelloWorldBlockAdminhtmlHelloWorld;
  4.  
  5. class Edit extends MagentoBackendBlockWidgetFormContainer
  6. {
  7. /**
  8. * Core registry
  9. *
  10. * @var MagentoFrameworkRegistry
  11. */
  12. protected $_coreRegistry = null;
  13.  
  14. /**
  15. * @param MagentoBackendBlockWidgetContext $context
  16. * @param MagentoFrameworkRegistry $registry
  17. * @param array $data
  18. */
  19. public function __construct(
  20. MagentoBackendBlockWidgetContext $context,
  21. MagentoFrameworkRegistry $registry,
  22. array $data = []
  23. ) {
  24. $this->_coreRegistry = $registry;
  25. parent::__construct($context, $data);
  26. }
  27.  
  28. /**
  29. * Initialize blog post edit block
  30. *
  31. * @return void
  32. */
  33. protected function _construct()
  34. {
  35.  
  36. $this->_objectId = 'helloworld_id';
  37. $this->_blockGroup = 'Learning_HelloWorld';
  38. $this->_controller = 'adminhtml_hello';
  39.  
  40. parent::_construct();
  41.  
  42. $this->buttonList->update('save', 'label', __('Save Record'));
  43. $this->buttonList->add(
  44. 'saveandcontinue',
  45. [
  46. 'label' => __('Save and Continue Edit'),
  47. 'class' => 'save',
  48. 'data_attribute' => [
  49. 'mage-init' => [
  50. 'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'],
  51. ],
  52. ]
  53. ],
  54. -100
  55. );
  56.  
  57. $this->buttonList->update('delete', 'label', __('Delete Record'));
  58. }
  59.  
  60. /**
  61. * Retrieve text for header element depending on loaded post
  62. *
  63. * @return MagentoFrameworkPhrase
  64. */
  65. public function getHeaderText()
  66. {
  67. if ($this->_coreRegistry->registry('hello_world')->getId()) {
  68. return __("Edit Record '%1'", $this->escapeHtml($this->_coreRegistry->registry('hello_world')->getTitle()));
  69. } else {
  70. return __('New Record');
  71. }
  72. }
  73.  
  74. /**
  75. * Getter of url for "Save and Continue" button
  76. * tab_id will be replaced by desired by JS later
  77. *
  78. * @return string
  79. */
  80. protected function _getSaveAndContinueUrl()
  81. {
  82. return $this->getUrl('helloworld/*/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '{{tab_id}}']);
  83. }
  84.  
  85. /**
  86. * Prepare layout
  87. *
  88. * @return MagentoFrameworkViewElementAbstractBlock
  89. */
  90. protected function _prepareLayout()
  91. {
  92. $this->_formScripts[] = "
  93. function toggleEditor() {
  94. if (tinyMCE.getInstanceById('page_content') == null) {
  95. tinyMCE.execCommand('mceAddControl', false, 'content');
  96. } else {
  97. tinyMCE.execCommand('mceRemoveControl', false, 'content');
  98. }
  99. };
  100. ";
  101. return parent::_prepareLayout();
  102. }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement