This Is Edit.php file
Magneto\BookFreeLayout\Block\Adminhtml\Demo\Edit.php
<?php
namespace Magneto\BookFreeLayout\Block\Adminhtml\Demo;
class Edit extends \Magento\Backend\Block\Widget\Form\Container
{
/**
* Core registry
*
* @var \Magento\Framework\Registry
*/
protected $_coreRegistry = null;
protected $_optionType;
/**
* @param \Magento\Backend\Block\Widget\Context $context
* @param \Magento\Framework\Registry $registry
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
\Magento\Framework\Registry $registry,
array $data = []
) {
$this->_coreRegistry = $registry;
parent::__construct($context, $data);
}
/**
* Initialize cms page edit block
*
* @return void
*/
protected function _construct()
{
// /die("hello");
$this->_objectId = 'id';
$this->_blockGroup = 'Magneto_BookFreeLayout';
$this->_controller = 'adminhtml_demo';
parent::_construct();
// $this->buttonList->update('save', 'label', __('Save Fields'));
// $this->buttonList->add(
// 'saveandcontinue',
// [
// 'label' => __('Save and Continue Edit'),
// 'class' => 'save',
// 'data_attribute' => [
// 'mage-init' => [
// 'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'],
// ],
// ]
// ],
// -100
// );
$this->buttonList->remove('delete');
}
/**
* Retrieve text for header element depending on loaded page
*
* @return \Magento\Framework\Phrase
*/
public function getHeaderText()
{
}
/**
* Check permission for passed action
*
* @param string $resourceId
* @return bool
*/
protected function _isAllowedAction($Id)
{
return $this->_authorization->isAllowed($Id);
}
/**
* 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('bookfreelayout/*/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '{{tab_id}}']);
}
/**
* Prepare form Html. call the phtm file with form.
*
* @return string
*/
public function getFormHtml()
{
// get the current form as html content.
// die("hello1");
$html = parent::getFormHtml();
//Append the phtml file after the form content.
// $html .= $this->setTemplate('Magneto_BookFreeLayout::demo/demo.phtml')->toHtml();
// return $html;
}
/**
* Prepare layout
*
* @return \Magento\Framework\View\Element\AbstractBlock
*/
protected function _prepareLayout()
{
// die("hello");
$this->_formScripts[] = "
require([
'jquery',
'mage/mage',
'knockout'
], function ($){
});
";
return parent::_prepareLayout();
}
}
This Is Form file From where i am creating admin form
Magneto\BookFreeLayout\Block\Adminhtml\Demo\Edit\Form.php
<?php
namespace Magneto\BookFreeLayout\Block\Adminhtml\Demo\Edit;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Backend\Block\Widget\Tab\TabInterface;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Registry;
use Magento\Framework\Data\FormFactory;
use Magento\Cms\Model\Wysiwyg\Config;
[![enter image description here][1]][1]// use Magneto\BookFreeLayout\Model\A\Config\Status;
class Form extends Generic implements TabInterface
{
protected $_wysiwygConfig;
/**
* @var \Magneto\BookFreeLayout\Model\Config\Status
*/
// protected $_newsStatus;
public function __construct(
Context $context,
Registry $registry,
FormFactory $formFactory,
Config $wysiwygConfig,
// Status $newsStatus,
array $data = []
) {
$this->_wysiwygConfig = $wysiwygConfig;
// $this->_newsStatus = $newsStatus;
parent::__construct($context, $registry, $formFactory, $data);
}
/**
* Prepare form fields
*
* @return \Magento\Backend\Block\Widget\Form
*/
protected function _prepareForm()
{
// die("joooo");
/** @var $model \Magneto\BookFreeLayout\Model\News */
$model = $this->_coreRegistry->registry('Alllayout');
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix('freelayout_');
$form->setFieldNameSuffix('freelayout');
$fieldset = $form->addFieldset(
'base_fieldset',
['legend' => __('General')]
);
if ($model->getId()) {
$fieldset->addField(
'id',
'hidden',
['name' => 'id']
);
}
$fieldset->addField(
'title',
'text',
[
'name' => 'title',
'label' => __('Title'),
'required' => true
]
);
// $fieldset->addField(
// 'status',
// 'select',
// [
// 'name' => 'status',
// 'label' => __('Status'),
// 'options' => $this->_newsStatus->toOptionArray()
// ]
// );
$fieldset->addField(
'summary',
'textarea',
[
'name' => 'summary',
'label' => __('Summary'),
'required' => true,
'style' => 'height: 15em; width: 30em;'
]
);
$wysiwygConfig = $this->_wysiwygConfig->getConfig();
$fieldset->addField(
'description',
'editor',
[
'name' => 'description',
'label' => __('Description'),
'required' => true,
'config' => $wysiwygConfig
]
);
$data = $model->getData();
$form->setValues($data);
$this->setForm($form);
return parent::_prepareForm();
}
/**
* Prepare label for tab
*
* @return string
*/
public function getTabLabel()
{
return __('News Info');
}
/**
* Prepare title for tab
*
* @return string
*/
public function getTabTitle()
{
return __('News Info');
}
/**
* {@inheritdoc}
*/
public function canShowTab()
{
return true;
}
/**
* {@inheritdoc}
*/
public function isHidden()
{
return false;
}
}