Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace LearningHelloWorldBlockAdminhtmlHelloWorld;
- class Edit extends MagentoBackendBlockWidgetFormContainer
- {
- /**
- * Core registry
- *
- * @var MagentoFrameworkRegistry
- */
- protected $_coreRegistry = null;
- /**
- * @param MagentoBackendBlockWidgetContext $context
- * @param MagentoFrameworkRegistry $registry
- * @param array $data
- */
- public function __construct(
- MagentoBackendBlockWidgetContext $context,
- MagentoFrameworkRegistry $registry,
- array $data = []
- ) {
- $this->_coreRegistry = $registry;
- parent::__construct($context, $data);
- }
- /**
- * Initialize blog post edit block
- *
- * @return void
- */
- protected function _construct()
- {
- $this->_objectId = 'helloworld_id';
- $this->_blockGroup = 'Learning_HelloWorld';
- $this->_controller = 'adminhtml_hello';
- parent::_construct();
- $this->buttonList->update('save', 'label', __('Save Record'));
- $this->buttonList->add(
- 'saveandcontinue',
- [
- 'label' => __('Save and Continue Edit'),
- 'class' => 'save',
- 'data_attribute' => [
- 'mage-init' => [
- 'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'],
- ],
- ]
- ],
- -100
- );
- $this->buttonList->update('delete', 'label', __('Delete Record'));
- }
- /**
- * Retrieve text for header element depending on loaded post
- *
- * @return MagentoFrameworkPhrase
- */
- public function getHeaderText()
- {
- if ($this->_coreRegistry->registry('hello_world')->getId()) {
- return __("Edit Record '%1'", $this->escapeHtml($this->_coreRegistry->registry('hello_world')->getTitle()));
- } else {
- return __('New Record');
- }
- }
- /**
- * Getter of url for "Save and Continue" button
- * tab_id will be replaced by desired by JS later
- *
- * @return string
- */
- protected function _getSaveAndContinueUrl()
- {
- return $this->getUrl('helloworld/*/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '{{tab_id}}']);
- }
- /**
- * Prepare layout
- *
- * @return MagentoFrameworkViewElementAbstractBlock
- */
- protected function _prepareLayout()
- {
- $this->_formScripts[] = "
- function toggleEditor() {
- if (tinyMCE.getInstanceById('page_content') == null) {
- tinyMCE.execCommand('mceAddControl', false, 'content');
- } else {
- tinyMCE.execCommand('mceRemoveControl', false, 'content');
- }
- };
- ";
- return parent::_prepareLayout();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement