Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace vendor nameModule nameBlockAdminhtmlBackgroundImageEdit;
- class Form extends MagentoBackendBlockWidgetFormGeneric
- {
- /**
- * Prepare form
- *
- * @return $this
- */
- public function _prepareForm()
- {
- /** @var MagentoFrameworkDataForm $form */
- $form = $this->_formFactory->create(
- [
- 'data' => [
- 'id' => 'edit_form',
- 'action' => $this->getData('action'),
- 'method' => 'post',
- 'enctype' => 'multipart/form-data'
- ]
- ]
- );
- $form->setUseContainer(true);
- $this->setForm($form);
- return parent::_prepareForm();
- }
- }
- namespace FvendorNamemoduleNameBlockAdminhtmlBackgroundImage;
- class Edit extends MagentoBackendBlockWidgetFormContainer
- {
- protected $_coreRegistry = null;
- public function __construct(
- MagentoBackendBlockWidgetContext $context,
- MagentoFrameworkRegistry $registry,
- array $data = []
- ) {
- $this->_coreRegistry = $registry;
- parent::__construct($context, $data);
- }
- protected function _construct()
- {
- $this->_objectId = 'backgroundimage_id';
- $this->_blockGroup = 'FME_BackgroundImage';
- $this->_controller = 'adminhtml_backgroundImage';
- parent::_construct();
- if ($this->_isAllowedAction('FME_BackgroundImage::save')) {
- $this->buttonList->update('save', 'label', __('Save Image'));
- $this->buttonList->add(
- 'saveandcontinue',
- [
- 'label' => __('Save and Continue Edit'),
- 'class' => 'save',
- 'data_attribute' => [
- 'mage-init' => [
- 'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'],
- ],
- ]
- ],
- -100
- );
- } else {
- $this->buttonList->remove('save');
- }
- }
- /**
- * Retrieve text for header element depending on loaded page
- *
- * @return string
- */
- public function getHeaderText()
- {
- if ($this->_coreRegistry->registry('backgroundimage')->getId()) {
- return __(
- "Edit BackgroundImage '%1'",
- $this->escapeHtml($this->_coreRegistry->registry('backgroundimage')->getTitle())
- );
- } else {
- return __('New BackgroundImage');
- }
- }
- /**
- * Check permission for passed action
- *
- * @param string $resourceId
- * @return bool
- */
- public function _isAllowedAction($resourceId)
- {
- return $this->_authorization->isAllowed($resourceId);
- }
- /**
- * Getter of url for "Save and Continue" button
- * tab_id will be replaced by desired by JS later
- *
- * @return string
- */
- public function _getSaveAndContinueUrl()
- {
- return $this->getUrl(
- 'backgroundimage/*/save',
- ['_current' => true, 'back' => 'edit', 'active_tab' => '{{tab_id}}']
- );
- }
- public function getFormActionUrl()
- {
- if ($this->hasFormActionUrl()) {
- return $this->getData('form_action_url');
- }
- return $this->getUrl('*/*/save');
- }
- /**
- * Prepare layout
- *
- * @return MagentoFrameworkViewElementAbstractBlock
- */
- public function _prepareLayout()
- {
- $this->_formScripts[] = "
- function toggleEditor() {
- if (tinyMCE.getInstanceById('page_content') == null) {
- tinyMCE.execCommand('mceAddControl', false, 'page_content');
- } else {
- tinyMCE.execCommand('mceRemoveControl', false, 'page_content');
- }
- };
- ";
- return parent::_prepareLayout();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement