Custom Admin Edit form Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2 admin form controller errorMagento 2 Add new field to Magento_User admin formForm is not displayed on panel admin Magento 2Magento 2: Add a product to the cart programmaticallyMagento 2 Create dynamic array From different Model Collection to use in multi select in gridmagento 2.2.5: Adding Custom Attribute to Customer Edit Form in AdminChange value of text field in admin form based on option selected in dropdownMagento 2.3 Can't view module's front end page output?

Putting Ant-Man on house arrest

Should man-made satellites feature an intelligent inverted "cow catcher"?

Like totally amazing interchangeable sister outfit accessory swapping or whatever

How to ask rejected full-time candidates to apply to teach individual courses?

Compiling and throwing simple dynamic exceptions at runtime for JVM

Does the Pact of the Blade warlock feature allow me to customize the properties of the pact weapon I create?

Can 'non' with gerundive mean both lack of obligation and negative obligation?

Who's this lady in the war room?

Can the van der Waals coefficients be negative in the van der Waals equation for real gases?

Determine the generator of an ideal of ring of integers

What is the difference between 准时 and 按时?

Is Bran literally the world's memory?

Why aren't these two solutions equivalent? Combinatorics problem

Weaponising the Grasp-at-a-Distance spell

Suing a Police Officer Instead of the Police Department

What helicopter has the most rotor blades?

How to charge percentage of transaction cost?

Can gravitational waves pass through a black hole?

Does using the Inspiration rules for character defects encourage My Guy Syndrome?

How to create a command for the "strange m" symbol in latex?

tabularx column has extra padding at right?

Is there a verb for listening stealthily?

Why does BitLocker not use RSA?

Does Prince Arnaud cause someone holding the Princess to lose?



Custom Admin Edit form



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2 admin form controller errorMagento 2 Add new field to Magento_User admin formForm is not displayed on panel admin Magento 2Magento 2: Add a product to the cart programmaticallyMagento 2 Create dynamic array From different Model Collection to use in multi select in gridmagento 2.2.5: Adding Custom Attribute to Customer Edit Form in AdminChange value of text field in admin form based on option selected in dropdownMagento 2.3 Can't view module's front end page output?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm having some difficulty setting up an edit form within my custom module, when i inspect i see the header "New Manufacturer", but the div which would typically be rendered with the class "page-content" is missing.enter image description here



I've specified the block as below:



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="editor"/>
<body>
<referenceContainer name="content">
<block class="AmritaManufacturerBlockAdminhtmlGridEdit" name="manufacturer_edit"/>
</referenceContainer>
</body>
</page>


The block looks like this:



<?php
namespace AmritaManufacturerBlockAdminhtmlGrid;

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 = 'manufacturer_id';
$this->_blockGroup = 'Amrita_Manufacturer';
$this->_controller = 'adminhtml_grid';


parent::_construct();

if ($this->_isAllowedAction('Amrita_Manufacturer::save_manufacturer'))
$this->buttonList->update('save', 'label', __('Save Manufacturer'));
$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');


if ($this->_isAllowedAction('Amrita_Manufacturer::delete_manufacturer'))
$this->buttonList->update('delete', 'label', __('Delete Manufacturer'));
else
$this->buttonList->remove('delete');



public function getModel()

return $this->_coreRegistry->registry('manufacturer_grid');


public function getHeaderText()

if ($this->getModel()->getId())
return __("Edit Manufacturer '%1'", $this->escapeHtml($this->getModel()->getTitle()));
else
return __('New Manufacturer');



/**
* Check permission for passed action
*
* @param string $resourceId
* @return bool
*/
protected 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
*/
protected function _getSaveAndContinueUrl()

return $this->getUrl('manufacturer/*/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '']);




The Form.php is as follows:



<?php

namespace AmritaManufacturerBlockAdminhtmlGridEdit;

use MagentoBackendBlockWidgetFormGeneric;

class Form extends Generic


/**
* @var MagentoStoreModelSystemStore
*/
protected $_systemStore;
/**
* @param MagentoBackendBlockTemplateContext $context
* @param MagentoFrameworkRegistry $registry
* @param MagentoFrameworkDataFormFactory $formFactory
* @param MagentoCmsModelWysiwygConfig $wysiwygConfig
* @param MagentoStoreModelSystemStore $systemStore
* @param array $data
*/
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoFrameworkRegistry $registry,
MagentoFrameworkDataFormFactory $formFactory,
MagentoStoreModelSystemStore $systemStore,
array $data = []
)
$this->_systemStore = $systemStore;
parent::__construct($context, $registry, $formFactory, $data);


/**
* Init form
*
* @return void
*/
protected function _construct()

parent::_construct();
$this->setId('manufacturer_form');
$this->setTitle(__('Manufacturer Information'));


public function getModel()

return $this->_coreRegistry->registry('manufacturer_grid');


/**
* Prepare form
*
* @return $this
*/
protected function _prepareForm()

$model = $this->getModel();

/** @var MagentoFrameworkDataForm $form */
$form = $this->_formFactory->create(
['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
);

$form->setHtmlIdPrefix('manufacturer_');

$fieldset = $form->addFieldset(
'base_fieldset',
['legend' => __('General Information'), 'class' => 'fieldset-wide']
);

if ($model->getManufacturerId())
$fieldset->addField('manufacturer_id', 'hidden', ['name' => 'manufacturer_id']);


$fieldset->addField(
'title',
'text',
['name' => 'title', 'label' => __('Manufacturer Title'), 'title' => __('Manufacturer Title'), 'required' => true]
);

$fieldset->addField(
'description',
'editor',
[
'name' => 'description',
'label' => __('Description'),
'title' => __('Description'),
'style' => 'height:36em',
'required' => true
]
);

$fieldset->addField(
'is_enabled',
'select',
[
'label' => __('Status'),
'title' => __('Status'),
'name' => 'is_enabled',
'required' => true,
'options' => ['1' => __('Enabled'), '0' => __('Disabled')]
]
);
if (!$model->getId())
$model->setData('is_enabled', '1');


$fieldset->addField(
'is_restricted',
'select',
[
'label' => __('Product Permissions'),
'title' => __('Product Permissions'),
'name' => 'is_restricted',
'required' => true,
'options' => ['1' => __('Restricted'), '0' => __('Unrestricted')]
]
);
if (!$model->getId())
$model->setData('is_restricted', '1');


$form->setValues($model->getData());
$form->setUseContainer(true);
$this->setForm($form);

return parent::_prepareForm();




The new action is as follows:



<?php
namespace AmritaManufacturerControllerAdminhtmlGrid;

class NewAction extends MagentoBackendAppAction


protected $resultForwardFactory;

public function __construct(
MagentoBackendAppActionContext $context,
MagentoBackendModelViewResultForwardFactory $resultForwardFactory
)
$this->resultForwardFactory = $resultForwardFactory;
parent::__construct($context);


public function execute()

/** @var MagentoBackendModelViewResultForward $resultForward */
$resultForward = $this->resultForwardFactory->create();
return $resultForward->forward('edit');


protected function _isAllowed()

return $this->_authorization->isAllowed('Amrita_Manufacturer::save_manufacturer');




The edit action is as follows:



<?php
namespace AmritaManufacturerControllerAdminhtmlGrid;

use MagentoBackendAppAction;

class Edit extends MagentoBackendAppAction
MagentoBackendModelViewResultRedirect
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function execute()

$id = $this->getRequest()->getParam('manufacturer_id');
$model = $this->_objectManager->create('AmritaManufacturerModelManufacturer');

if ($id)
$model->load($id);
if (!$model->getId())
$this->messageManager->addError(__('This manufacturer no longer exists.'));
/** MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();

return $resultRedirect->setPath('*/*/');



$data = $this->_objectManager->get('MagentoBackendModelSession')->getFormData(true);
if (!empty($data))
$model->setData($data);


$this->_coreRegistry->register('manufacturer_grid', $model);

/** @var MagentoBackendModelViewResultPage $resultPage */
$resultPage = $this->_initAction();
$resultPage->addBreadcrumb(
$id ? __('Edit Manufacturer') : __('New Manufacturer'),
$id ? __('Edit Manufacturer') : __('New Manufacturer')
);
$resultPage->getConfig()->getTitle()->prepend(__('Manufacturers'));
$resultPage->getConfig()->getTitle()
->prepend($model->getId() ? $model->getTitle() : __('New Manufacturer'));

return $resultPage;




I have a few questions:



  1. the method getManufacturerId() in the form.php, where/how is
    this defined.

  2. what should I add to the core registry? Is it the Cache_tag as
    defined in the model Manufacturer.php?
    $this->_coreRegistry->registry('manufacturer_grid');









share|improve this question
















bumped to the homepage by Community 31 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.





















    0















    I'm having some difficulty setting up an edit form within my custom module, when i inspect i see the header "New Manufacturer", but the div which would typically be rendered with the class "page-content" is missing.enter image description here



    I've specified the block as below:



    <?xml version="1.0"?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="editor"/>
    <body>
    <referenceContainer name="content">
    <block class="AmritaManufacturerBlockAdminhtmlGridEdit" name="manufacturer_edit"/>
    </referenceContainer>
    </body>
    </page>


    The block looks like this:



    <?php
    namespace AmritaManufacturerBlockAdminhtmlGrid;

    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 = 'manufacturer_id';
    $this->_blockGroup = 'Amrita_Manufacturer';
    $this->_controller = 'adminhtml_grid';


    parent::_construct();

    if ($this->_isAllowedAction('Amrita_Manufacturer::save_manufacturer'))
    $this->buttonList->update('save', 'label', __('Save Manufacturer'));
    $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');


    if ($this->_isAllowedAction('Amrita_Manufacturer::delete_manufacturer'))
    $this->buttonList->update('delete', 'label', __('Delete Manufacturer'));
    else
    $this->buttonList->remove('delete');



    public function getModel()

    return $this->_coreRegistry->registry('manufacturer_grid');


    public function getHeaderText()

    if ($this->getModel()->getId())
    return __("Edit Manufacturer '%1'", $this->escapeHtml($this->getModel()->getTitle()));
    else
    return __('New Manufacturer');



    /**
    * Check permission for passed action
    *
    * @param string $resourceId
    * @return bool
    */
    protected 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
    */
    protected function _getSaveAndContinueUrl()

    return $this->getUrl('manufacturer/*/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '']);




    The Form.php is as follows:



    <?php

    namespace AmritaManufacturerBlockAdminhtmlGridEdit;

    use MagentoBackendBlockWidgetFormGeneric;

    class Form extends Generic


    /**
    * @var MagentoStoreModelSystemStore
    */
    protected $_systemStore;
    /**
    * @param MagentoBackendBlockTemplateContext $context
    * @param MagentoFrameworkRegistry $registry
    * @param MagentoFrameworkDataFormFactory $formFactory
    * @param MagentoCmsModelWysiwygConfig $wysiwygConfig
    * @param MagentoStoreModelSystemStore $systemStore
    * @param array $data
    */
    public function __construct(
    MagentoBackendBlockTemplateContext $context,
    MagentoFrameworkRegistry $registry,
    MagentoFrameworkDataFormFactory $formFactory,
    MagentoStoreModelSystemStore $systemStore,
    array $data = []
    )
    $this->_systemStore = $systemStore;
    parent::__construct($context, $registry, $formFactory, $data);


    /**
    * Init form
    *
    * @return void
    */
    protected function _construct()

    parent::_construct();
    $this->setId('manufacturer_form');
    $this->setTitle(__('Manufacturer Information'));


    public function getModel()

    return $this->_coreRegistry->registry('manufacturer_grid');


    /**
    * Prepare form
    *
    * @return $this
    */
    protected function _prepareForm()

    $model = $this->getModel();

    /** @var MagentoFrameworkDataForm $form */
    $form = $this->_formFactory->create(
    ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
    );

    $form->setHtmlIdPrefix('manufacturer_');

    $fieldset = $form->addFieldset(
    'base_fieldset',
    ['legend' => __('General Information'), 'class' => 'fieldset-wide']
    );

    if ($model->getManufacturerId())
    $fieldset->addField('manufacturer_id', 'hidden', ['name' => 'manufacturer_id']);


    $fieldset->addField(
    'title',
    'text',
    ['name' => 'title', 'label' => __('Manufacturer Title'), 'title' => __('Manufacturer Title'), 'required' => true]
    );

    $fieldset->addField(
    'description',
    'editor',
    [
    'name' => 'description',
    'label' => __('Description'),
    'title' => __('Description'),
    'style' => 'height:36em',
    'required' => true
    ]
    );

    $fieldset->addField(
    'is_enabled',
    'select',
    [
    'label' => __('Status'),
    'title' => __('Status'),
    'name' => 'is_enabled',
    'required' => true,
    'options' => ['1' => __('Enabled'), '0' => __('Disabled')]
    ]
    );
    if (!$model->getId())
    $model->setData('is_enabled', '1');


    $fieldset->addField(
    'is_restricted',
    'select',
    [
    'label' => __('Product Permissions'),
    'title' => __('Product Permissions'),
    'name' => 'is_restricted',
    'required' => true,
    'options' => ['1' => __('Restricted'), '0' => __('Unrestricted')]
    ]
    );
    if (!$model->getId())
    $model->setData('is_restricted', '1');


    $form->setValues($model->getData());
    $form->setUseContainer(true);
    $this->setForm($form);

    return parent::_prepareForm();




    The new action is as follows:



    <?php
    namespace AmritaManufacturerControllerAdminhtmlGrid;

    class NewAction extends MagentoBackendAppAction


    protected $resultForwardFactory;

    public function __construct(
    MagentoBackendAppActionContext $context,
    MagentoBackendModelViewResultForwardFactory $resultForwardFactory
    )
    $this->resultForwardFactory = $resultForwardFactory;
    parent::__construct($context);


    public function execute()

    /** @var MagentoBackendModelViewResultForward $resultForward */
    $resultForward = $this->resultForwardFactory->create();
    return $resultForward->forward('edit');


    protected function _isAllowed()

    return $this->_authorization->isAllowed('Amrita_Manufacturer::save_manufacturer');




    The edit action is as follows:



    <?php
    namespace AmritaManufacturerControllerAdminhtmlGrid;

    use MagentoBackendAppAction;

    class Edit extends MagentoBackendAppAction
    MagentoBackendModelViewResultRedirect
    * @SuppressWarnings(PHPMD.NPathComplexity)
    */
    public function execute()

    $id = $this->getRequest()->getParam('manufacturer_id');
    $model = $this->_objectManager->create('AmritaManufacturerModelManufacturer');

    if ($id)
    $model->load($id);
    if (!$model->getId())
    $this->messageManager->addError(__('This manufacturer no longer exists.'));
    /** MagentoBackendModelViewResultRedirect $resultRedirect */
    $resultRedirect = $this->resultRedirectFactory->create();

    return $resultRedirect->setPath('*/*/');



    $data = $this->_objectManager->get('MagentoBackendModelSession')->getFormData(true);
    if (!empty($data))
    $model->setData($data);


    $this->_coreRegistry->register('manufacturer_grid', $model);

    /** @var MagentoBackendModelViewResultPage $resultPage */
    $resultPage = $this->_initAction();
    $resultPage->addBreadcrumb(
    $id ? __('Edit Manufacturer') : __('New Manufacturer'),
    $id ? __('Edit Manufacturer') : __('New Manufacturer')
    );
    $resultPage->getConfig()->getTitle()->prepend(__('Manufacturers'));
    $resultPage->getConfig()->getTitle()
    ->prepend($model->getId() ? $model->getTitle() : __('New Manufacturer'));

    return $resultPage;




    I have a few questions:



    1. the method getManufacturerId() in the form.php, where/how is
      this defined.

    2. what should I add to the core registry? Is it the Cache_tag as
      defined in the model Manufacturer.php?
      $this->_coreRegistry->registry('manufacturer_grid');









    share|improve this question
















    bumped to the homepage by Community 31 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

















      0












      0








      0








      I'm having some difficulty setting up an edit form within my custom module, when i inspect i see the header "New Manufacturer", but the div which would typically be rendered with the class "page-content" is missing.enter image description here



      I've specified the block as below:



      <?xml version="1.0"?>
      <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <update handle="editor"/>
      <body>
      <referenceContainer name="content">
      <block class="AmritaManufacturerBlockAdminhtmlGridEdit" name="manufacturer_edit"/>
      </referenceContainer>
      </body>
      </page>


      The block looks like this:



      <?php
      namespace AmritaManufacturerBlockAdminhtmlGrid;

      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 = 'manufacturer_id';
      $this->_blockGroup = 'Amrita_Manufacturer';
      $this->_controller = 'adminhtml_grid';


      parent::_construct();

      if ($this->_isAllowedAction('Amrita_Manufacturer::save_manufacturer'))
      $this->buttonList->update('save', 'label', __('Save Manufacturer'));
      $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');


      if ($this->_isAllowedAction('Amrita_Manufacturer::delete_manufacturer'))
      $this->buttonList->update('delete', 'label', __('Delete Manufacturer'));
      else
      $this->buttonList->remove('delete');



      public function getModel()

      return $this->_coreRegistry->registry('manufacturer_grid');


      public function getHeaderText()

      if ($this->getModel()->getId())
      return __("Edit Manufacturer '%1'", $this->escapeHtml($this->getModel()->getTitle()));
      else
      return __('New Manufacturer');



      /**
      * Check permission for passed action
      *
      * @param string $resourceId
      * @return bool
      */
      protected 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
      */
      protected function _getSaveAndContinueUrl()

      return $this->getUrl('manufacturer/*/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '']);




      The Form.php is as follows:



      <?php

      namespace AmritaManufacturerBlockAdminhtmlGridEdit;

      use MagentoBackendBlockWidgetFormGeneric;

      class Form extends Generic


      /**
      * @var MagentoStoreModelSystemStore
      */
      protected $_systemStore;
      /**
      * @param MagentoBackendBlockTemplateContext $context
      * @param MagentoFrameworkRegistry $registry
      * @param MagentoFrameworkDataFormFactory $formFactory
      * @param MagentoCmsModelWysiwygConfig $wysiwygConfig
      * @param MagentoStoreModelSystemStore $systemStore
      * @param array $data
      */
      public function __construct(
      MagentoBackendBlockTemplateContext $context,
      MagentoFrameworkRegistry $registry,
      MagentoFrameworkDataFormFactory $formFactory,
      MagentoStoreModelSystemStore $systemStore,
      array $data = []
      )
      $this->_systemStore = $systemStore;
      parent::__construct($context, $registry, $formFactory, $data);


      /**
      * Init form
      *
      * @return void
      */
      protected function _construct()

      parent::_construct();
      $this->setId('manufacturer_form');
      $this->setTitle(__('Manufacturer Information'));


      public function getModel()

      return $this->_coreRegistry->registry('manufacturer_grid');


      /**
      * Prepare form
      *
      * @return $this
      */
      protected function _prepareForm()

      $model = $this->getModel();

      /** @var MagentoFrameworkDataForm $form */
      $form = $this->_formFactory->create(
      ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
      );

      $form->setHtmlIdPrefix('manufacturer_');

      $fieldset = $form->addFieldset(
      'base_fieldset',
      ['legend' => __('General Information'), 'class' => 'fieldset-wide']
      );

      if ($model->getManufacturerId())
      $fieldset->addField('manufacturer_id', 'hidden', ['name' => 'manufacturer_id']);


      $fieldset->addField(
      'title',
      'text',
      ['name' => 'title', 'label' => __('Manufacturer Title'), 'title' => __('Manufacturer Title'), 'required' => true]
      );

      $fieldset->addField(
      'description',
      'editor',
      [
      'name' => 'description',
      'label' => __('Description'),
      'title' => __('Description'),
      'style' => 'height:36em',
      'required' => true
      ]
      );

      $fieldset->addField(
      'is_enabled',
      'select',
      [
      'label' => __('Status'),
      'title' => __('Status'),
      'name' => 'is_enabled',
      'required' => true,
      'options' => ['1' => __('Enabled'), '0' => __('Disabled')]
      ]
      );
      if (!$model->getId())
      $model->setData('is_enabled', '1');


      $fieldset->addField(
      'is_restricted',
      'select',
      [
      'label' => __('Product Permissions'),
      'title' => __('Product Permissions'),
      'name' => 'is_restricted',
      'required' => true,
      'options' => ['1' => __('Restricted'), '0' => __('Unrestricted')]
      ]
      );
      if (!$model->getId())
      $model->setData('is_restricted', '1');


      $form->setValues($model->getData());
      $form->setUseContainer(true);
      $this->setForm($form);

      return parent::_prepareForm();




      The new action is as follows:



      <?php
      namespace AmritaManufacturerControllerAdminhtmlGrid;

      class NewAction extends MagentoBackendAppAction


      protected $resultForwardFactory;

      public function __construct(
      MagentoBackendAppActionContext $context,
      MagentoBackendModelViewResultForwardFactory $resultForwardFactory
      )
      $this->resultForwardFactory = $resultForwardFactory;
      parent::__construct($context);


      public function execute()

      /** @var MagentoBackendModelViewResultForward $resultForward */
      $resultForward = $this->resultForwardFactory->create();
      return $resultForward->forward('edit');


      protected function _isAllowed()

      return $this->_authorization->isAllowed('Amrita_Manufacturer::save_manufacturer');




      The edit action is as follows:



      <?php
      namespace AmritaManufacturerControllerAdminhtmlGrid;

      use MagentoBackendAppAction;

      class Edit extends MagentoBackendAppAction
      MagentoBackendModelViewResultRedirect
      * @SuppressWarnings(PHPMD.NPathComplexity)
      */
      public function execute()

      $id = $this->getRequest()->getParam('manufacturer_id');
      $model = $this->_objectManager->create('AmritaManufacturerModelManufacturer');

      if ($id)
      $model->load($id);
      if (!$model->getId())
      $this->messageManager->addError(__('This manufacturer no longer exists.'));
      /** MagentoBackendModelViewResultRedirect $resultRedirect */
      $resultRedirect = $this->resultRedirectFactory->create();

      return $resultRedirect->setPath('*/*/');



      $data = $this->_objectManager->get('MagentoBackendModelSession')->getFormData(true);
      if (!empty($data))
      $model->setData($data);


      $this->_coreRegistry->register('manufacturer_grid', $model);

      /** @var MagentoBackendModelViewResultPage $resultPage */
      $resultPage = $this->_initAction();
      $resultPage->addBreadcrumb(
      $id ? __('Edit Manufacturer') : __('New Manufacturer'),
      $id ? __('Edit Manufacturer') : __('New Manufacturer')
      );
      $resultPage->getConfig()->getTitle()->prepend(__('Manufacturers'));
      $resultPage->getConfig()->getTitle()
      ->prepend($model->getId() ? $model->getTitle() : __('New Manufacturer'));

      return $resultPage;




      I have a few questions:



      1. the method getManufacturerId() in the form.php, where/how is
        this defined.

      2. what should I add to the core registry? Is it the Cache_tag as
        defined in the model Manufacturer.php?
        $this->_coreRegistry->registry('manufacturer_grid');









      share|improve this question
















      I'm having some difficulty setting up an edit form within my custom module, when i inspect i see the header "New Manufacturer", but the div which would typically be rendered with the class "page-content" is missing.enter image description here



      I've specified the block as below:



      <?xml version="1.0"?>
      <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <update handle="editor"/>
      <body>
      <referenceContainer name="content">
      <block class="AmritaManufacturerBlockAdminhtmlGridEdit" name="manufacturer_edit"/>
      </referenceContainer>
      </body>
      </page>


      The block looks like this:



      <?php
      namespace AmritaManufacturerBlockAdminhtmlGrid;

      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 = 'manufacturer_id';
      $this->_blockGroup = 'Amrita_Manufacturer';
      $this->_controller = 'adminhtml_grid';


      parent::_construct();

      if ($this->_isAllowedAction('Amrita_Manufacturer::save_manufacturer'))
      $this->buttonList->update('save', 'label', __('Save Manufacturer'));
      $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');


      if ($this->_isAllowedAction('Amrita_Manufacturer::delete_manufacturer'))
      $this->buttonList->update('delete', 'label', __('Delete Manufacturer'));
      else
      $this->buttonList->remove('delete');



      public function getModel()

      return $this->_coreRegistry->registry('manufacturer_grid');


      public function getHeaderText()

      if ($this->getModel()->getId())
      return __("Edit Manufacturer '%1'", $this->escapeHtml($this->getModel()->getTitle()));
      else
      return __('New Manufacturer');



      /**
      * Check permission for passed action
      *
      * @param string $resourceId
      * @return bool
      */
      protected 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
      */
      protected function _getSaveAndContinueUrl()

      return $this->getUrl('manufacturer/*/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '']);




      The Form.php is as follows:



      <?php

      namespace AmritaManufacturerBlockAdminhtmlGridEdit;

      use MagentoBackendBlockWidgetFormGeneric;

      class Form extends Generic


      /**
      * @var MagentoStoreModelSystemStore
      */
      protected $_systemStore;
      /**
      * @param MagentoBackendBlockTemplateContext $context
      * @param MagentoFrameworkRegistry $registry
      * @param MagentoFrameworkDataFormFactory $formFactory
      * @param MagentoCmsModelWysiwygConfig $wysiwygConfig
      * @param MagentoStoreModelSystemStore $systemStore
      * @param array $data
      */
      public function __construct(
      MagentoBackendBlockTemplateContext $context,
      MagentoFrameworkRegistry $registry,
      MagentoFrameworkDataFormFactory $formFactory,
      MagentoStoreModelSystemStore $systemStore,
      array $data = []
      )
      $this->_systemStore = $systemStore;
      parent::__construct($context, $registry, $formFactory, $data);


      /**
      * Init form
      *
      * @return void
      */
      protected function _construct()

      parent::_construct();
      $this->setId('manufacturer_form');
      $this->setTitle(__('Manufacturer Information'));


      public function getModel()

      return $this->_coreRegistry->registry('manufacturer_grid');


      /**
      * Prepare form
      *
      * @return $this
      */
      protected function _prepareForm()

      $model = $this->getModel();

      /** @var MagentoFrameworkDataForm $form */
      $form = $this->_formFactory->create(
      ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
      );

      $form->setHtmlIdPrefix('manufacturer_');

      $fieldset = $form->addFieldset(
      'base_fieldset',
      ['legend' => __('General Information'), 'class' => 'fieldset-wide']
      );

      if ($model->getManufacturerId())
      $fieldset->addField('manufacturer_id', 'hidden', ['name' => 'manufacturer_id']);


      $fieldset->addField(
      'title',
      'text',
      ['name' => 'title', 'label' => __('Manufacturer Title'), 'title' => __('Manufacturer Title'), 'required' => true]
      );

      $fieldset->addField(
      'description',
      'editor',
      [
      'name' => 'description',
      'label' => __('Description'),
      'title' => __('Description'),
      'style' => 'height:36em',
      'required' => true
      ]
      );

      $fieldset->addField(
      'is_enabled',
      'select',
      [
      'label' => __('Status'),
      'title' => __('Status'),
      'name' => 'is_enabled',
      'required' => true,
      'options' => ['1' => __('Enabled'), '0' => __('Disabled')]
      ]
      );
      if (!$model->getId())
      $model->setData('is_enabled', '1');


      $fieldset->addField(
      'is_restricted',
      'select',
      [
      'label' => __('Product Permissions'),
      'title' => __('Product Permissions'),
      'name' => 'is_restricted',
      'required' => true,
      'options' => ['1' => __('Restricted'), '0' => __('Unrestricted')]
      ]
      );
      if (!$model->getId())
      $model->setData('is_restricted', '1');


      $form->setValues($model->getData());
      $form->setUseContainer(true);
      $this->setForm($form);

      return parent::_prepareForm();




      The new action is as follows:



      <?php
      namespace AmritaManufacturerControllerAdminhtmlGrid;

      class NewAction extends MagentoBackendAppAction


      protected $resultForwardFactory;

      public function __construct(
      MagentoBackendAppActionContext $context,
      MagentoBackendModelViewResultForwardFactory $resultForwardFactory
      )
      $this->resultForwardFactory = $resultForwardFactory;
      parent::__construct($context);


      public function execute()

      /** @var MagentoBackendModelViewResultForward $resultForward */
      $resultForward = $this->resultForwardFactory->create();
      return $resultForward->forward('edit');


      protected function _isAllowed()

      return $this->_authorization->isAllowed('Amrita_Manufacturer::save_manufacturer');




      The edit action is as follows:



      <?php
      namespace AmritaManufacturerControllerAdminhtmlGrid;

      use MagentoBackendAppAction;

      class Edit extends MagentoBackendAppAction
      MagentoBackendModelViewResultRedirect
      * @SuppressWarnings(PHPMD.NPathComplexity)
      */
      public function execute()

      $id = $this->getRequest()->getParam('manufacturer_id');
      $model = $this->_objectManager->create('AmritaManufacturerModelManufacturer');

      if ($id)
      $model->load($id);
      if (!$model->getId())
      $this->messageManager->addError(__('This manufacturer no longer exists.'));
      /** MagentoBackendModelViewResultRedirect $resultRedirect */
      $resultRedirect = $this->resultRedirectFactory->create();

      return $resultRedirect->setPath('*/*/');



      $data = $this->_objectManager->get('MagentoBackendModelSession')->getFormData(true);
      if (!empty($data))
      $model->setData($data);


      $this->_coreRegistry->register('manufacturer_grid', $model);

      /** @var MagentoBackendModelViewResultPage $resultPage */
      $resultPage = $this->_initAction();
      $resultPage->addBreadcrumb(
      $id ? __('Edit Manufacturer') : __('New Manufacturer'),
      $id ? __('Edit Manufacturer') : __('New Manufacturer')
      );
      $resultPage->getConfig()->getTitle()->prepend(__('Manufacturers'));
      $resultPage->getConfig()->getTitle()
      ->prepend($model->getId() ? $model->getTitle() : __('New Manufacturer'));

      return $resultPage;




      I have a few questions:



      1. the method getManufacturerId() in the form.php, where/how is
        this defined.

      2. what should I add to the core registry? Is it the Cache_tag as
        defined in the model Manufacturer.php?
        $this->_coreRegistry->registry('manufacturer_grid');






      magento2 adminhtml adminform






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 27 '16 at 8:49









      Fabian Schmengler

      55.4k21139354




      55.4k21139354










      asked May 27 '16 at 8:29









      Sophie BaxterSophie Baxter

      190622




      190622





      bumped to the homepage by Community 31 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 31 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















          3 Answers
          3






          active

          oldest

          votes


















          0














          Because of $this->_coreRegistry->register(), invalid core registry your form is not loading. Your core registry should be your model class, like $this->_coreRegistry->register(modulename_modelclass);






          share|improve this answer
































            0














            Please make sure that your layout configuration file has the same namespace name with route front name. For example: your route front name is manufacturer, and your layout configuration file name is manufacturer_grid_edit.






            share|improve this answer






























              0














              You are missing layout defined in your xml file.
              set layout="admin-2columns-left" in your page tag.



              <?xml version="1.0"?>
              <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" layout="admin-2columns-left">
              <update handle="editor"/>
              <body>
              <referenceContainer name="content">
              <block class="AmritaManufacturerBlockAdminhtmlGridEdit" name="manufacturer_edit"/>
              </referenceContainer>
              </body>
              </page>





              share|improve this answer

























              • This hasn't resolved the problem. My assumption was that an admin layout would be specified by default. Also, in the example i'm following, no layout is specified. ashsmith.io/magento2/module-from-scratch-part-5-adminhtml

                – Sophie Baxter
                May 27 '16 at 11:04











              Your Answer








              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "479"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f117226%2fcustom-admin-edit-form%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              Because of $this->_coreRegistry->register(), invalid core registry your form is not loading. Your core registry should be your model class, like $this->_coreRegistry->register(modulename_modelclass);






              share|improve this answer





























                0














                Because of $this->_coreRegistry->register(), invalid core registry your form is not loading. Your core registry should be your model class, like $this->_coreRegistry->register(modulename_modelclass);






                share|improve this answer



























                  0












                  0








                  0







                  Because of $this->_coreRegistry->register(), invalid core registry your form is not loading. Your core registry should be your model class, like $this->_coreRegistry->register(modulename_modelclass);






                  share|improve this answer















                  Because of $this->_coreRegistry->register(), invalid core registry your form is not loading. Your core registry should be your model class, like $this->_coreRegistry->register(modulename_modelclass);







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 1 '16 at 14:41









                  7ochem

                  5,86493770




                  5,86493770










                  answered Nov 1 '16 at 14:22









                  rajat kararajat kara

                  662521




                  662521























                      0














                      Please make sure that your layout configuration file has the same namespace name with route front name. For example: your route front name is manufacturer, and your layout configuration file name is manufacturer_grid_edit.






                      share|improve this answer



























                        0














                        Please make sure that your layout configuration file has the same namespace name with route front name. For example: your route front name is manufacturer, and your layout configuration file name is manufacturer_grid_edit.






                        share|improve this answer

























                          0












                          0








                          0







                          Please make sure that your layout configuration file has the same namespace name with route front name. For example: your route front name is manufacturer, and your layout configuration file name is manufacturer_grid_edit.






                          share|improve this answer













                          Please make sure that your layout configuration file has the same namespace name with route front name. For example: your route front name is manufacturer, and your layout configuration file name is manufacturer_grid_edit.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 10 '17 at 6:57









                          Hùng Thế HiểnHùng Thế Hiển

                          17916




                          17916





















                              0














                              You are missing layout defined in your xml file.
                              set layout="admin-2columns-left" in your page tag.



                              <?xml version="1.0"?>
                              <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                              xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" layout="admin-2columns-left">
                              <update handle="editor"/>
                              <body>
                              <referenceContainer name="content">
                              <block class="AmritaManufacturerBlockAdminhtmlGridEdit" name="manufacturer_edit"/>
                              </referenceContainer>
                              </body>
                              </page>





                              share|improve this answer

























                              • This hasn't resolved the problem. My assumption was that an admin layout would be specified by default. Also, in the example i'm following, no layout is specified. ashsmith.io/magento2/module-from-scratch-part-5-adminhtml

                                – Sophie Baxter
                                May 27 '16 at 11:04















                              0














                              You are missing layout defined in your xml file.
                              set layout="admin-2columns-left" in your page tag.



                              <?xml version="1.0"?>
                              <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                              xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" layout="admin-2columns-left">
                              <update handle="editor"/>
                              <body>
                              <referenceContainer name="content">
                              <block class="AmritaManufacturerBlockAdminhtmlGridEdit" name="manufacturer_edit"/>
                              </referenceContainer>
                              </body>
                              </page>





                              share|improve this answer

























                              • This hasn't resolved the problem. My assumption was that an admin layout would be specified by default. Also, in the example i'm following, no layout is specified. ashsmith.io/magento2/module-from-scratch-part-5-adminhtml

                                – Sophie Baxter
                                May 27 '16 at 11:04













                              0












                              0








                              0







                              You are missing layout defined in your xml file.
                              set layout="admin-2columns-left" in your page tag.



                              <?xml version="1.0"?>
                              <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                              xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" layout="admin-2columns-left">
                              <update handle="editor"/>
                              <body>
                              <referenceContainer name="content">
                              <block class="AmritaManufacturerBlockAdminhtmlGridEdit" name="manufacturer_edit"/>
                              </referenceContainer>
                              </body>
                              </page>





                              share|improve this answer















                              You are missing layout defined in your xml file.
                              set layout="admin-2columns-left" in your page tag.



                              <?xml version="1.0"?>
                              <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                              xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" layout="admin-2columns-left">
                              <update handle="editor"/>
                              <body>
                              <referenceContainer name="content">
                              <block class="AmritaManufacturerBlockAdminhtmlGridEdit" name="manufacturer_edit"/>
                              </referenceContainer>
                              </body>
                              </page>






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Apr 27 '17 at 5:31

























                              answered May 27 '16 at 8:37









                              Rakesh JesadiyaRakesh Jesadiya

                              30.5k1577126




                              30.5k1577126












                              • This hasn't resolved the problem. My assumption was that an admin layout would be specified by default. Also, in the example i'm following, no layout is specified. ashsmith.io/magento2/module-from-scratch-part-5-adminhtml

                                – Sophie Baxter
                                May 27 '16 at 11:04

















                              • This hasn't resolved the problem. My assumption was that an admin layout would be specified by default. Also, in the example i'm following, no layout is specified. ashsmith.io/magento2/module-from-scratch-part-5-adminhtml

                                – Sophie Baxter
                                May 27 '16 at 11:04
















                              This hasn't resolved the problem. My assumption was that an admin layout would be specified by default. Also, in the example i'm following, no layout is specified. ashsmith.io/magento2/module-from-scratch-part-5-adminhtml

                              – Sophie Baxter
                              May 27 '16 at 11:04





                              This hasn't resolved the problem. My assumption was that an admin layout would be specified by default. Also, in the example i'm following, no layout is specified. ashsmith.io/magento2/module-from-scratch-part-5-adminhtml

                              – Sophie Baxter
                              May 27 '16 at 11:04

















                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Magento Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f117226%2fcustom-admin-edit-form%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Magento 2 duplicate PHPSESSID cookie when using session_start() in custom php scriptMagento 2: User cant logged in into to account page, no error showing!Magento duplicate on subdomainGrabbing storeview from cookie (after using language selector)How do I run php custom script on magento2Magento 2: Include PHP script in headerSession lock after using Cm_RedisSessionscript php to update stockMagento set cookie popupMagento 2 session id cookie - where to find it?How to import Configurable product from csv with custom attributes using php scriptMagento 2 run custom PHP script

                              Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

                              How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2