Is there a way to debug errors like Invalid block type: Magento\Backend\Block\Empty\Edit\Form?

magento.stackexchange https://magento.stackexchange.com/questions/116079

  •  29-09-2020
  •  | 
  •  

Question

Therer is a way to debug more easily errors like Invalid block type: Magento\Backend\Block\Empty\Edit\Form?

Im trying to kind of clone the functionality of module-sales-rule module, for practicing but im getting this error when accesing my custom form.

Invalid block type: Magento\Backend\Block\Empty\Edit\Form
    #0 /var/www/magento2_conector/vendor/magento/framework/View/Layout/Generator/Block.php(237): Magento\Framework\View\Layout\Generator\Block->getBlockInstance('Magento\\Backend...', Array)
    #1 /var/www/magento2_conector/vendor/magento/framework/View/Layout.php(760): Magento\Framework\View\Layout\Generator\Block->createBlock('Magento\\Backend...', 'promo_coupons...', Array)
    #2 /var/www/magento2_conector/vendor/magento/framework/View/Layout.php(743): Magento\Framework\View\Layout->_createBlock('Magento\\Backend...', 'promo_coupons...', Array)
    #3 /var/www/magento2_conector/var/generation/Magento/Framework/View/Layout/Interceptor.php(349): Magento\Framework\View\Layout->createBlock('Magento\\Backend...', 'promo_coupons...', Array)
    #4 /var/www/magento2_conector/vendor/magento/framework/View/Element/AbstractBlock.php(380): Magento\Framework\View\Layout\Interceptor->createBlock('Magento\\Backend...', 'promo_coupons...', Array)
    #5 /var/www/magento2_conector/vendor/magento/module-backend/Block/Widget/Form/Container.php(108): Magento\Framework\View\Element\AbstractBlock->addChild('form', 'Magento\\Backend...')
    #6 /var/www/magento2_conector/vendor/magento/framework/View/Element/AbstractBlock.php(262): Magento\Backend\Block\Widget\Form\Container->_prepareLayout()
    #7 /var/www/magento2_conector/vendor/magento/framework/View/Layout/Generator/Block.php(139): Magento\Framework\View\Element\AbstractBlock->setLayout(Object(Magento\Framework\View\Layout\Interceptor))
    #8 /var/www/magento2_conector/vendor/magento/framework/View/Layout/GeneratorPool.php(86): Magento\Framework\View\Layout\Generator\Block->process(Object(Magento\Framework\View\Layout\Reader\Context), Object(Magento\Framework\View\Layout\Generator\Context))
    #9 /var/www/magento2_conector/vendor/magento/framework/View/Layout.php(327): Magento\Framework\View\Layout\GeneratorPool->process(Object(Magento\Framework\View\Layout\Reader\Context), Object(Magento\Framework\View\Layout\Generator\Context))
    #10 /var/www/magento2_conector/var/generation/Magento/Framework/View/Layout/Interceptor.php(89): Magento\Framework\View\Layout->generateElements()
    #11 /var/www/magento2_conector/vendor/magento/framework/View/Layout/Builder.php(129): Magento\Framework\View\Layout\Interceptor->generateElements()
    #12 /var/www/magento2_conector/vendor/magento/framework/View/Page/Builder.php(55): Magento\Framework\View\Layout\Builder->generateLayoutBlocks()
    #13 /var/www/magento2_conector/vendor/magento/framework/View/Layout/Builder.php(65): Magento\Framework\View\Page\Builder->generateLayoutBlocks()
    #14 /var/www/magento2_conector/vendor/magento/framework/View/Page/Config.php(166): Magento\Framework\View\Layout\Builder->build()
    #15 /var/www/magento2_conector/vendor/magento/framework/View/Page/Config.php(176): Magento\Framework\View\Page\Config->build()
    #16 /var/www/magento2_conector/vendor/magento/framework/View/Result/Page.php(225): Magento\Framework\View\Page\Config->publicBuild()
    #17 /var/www/magento2_conector/vendor/magento/framework/View/Result/Layout.php(162): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
    #18 /var/www/magento2_conector/var/generation/Magento/Backend/Model/View/Result/Page/Interceptor.php(193): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
    #19 /var/www/magento2_conector/vendor/magento/framework/App/Http.php(119): Magento\Backend\Model\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
    #20 /var/www/magento2_conector/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
    #21 /var/www/magento2_conector/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))

I have a controller NewAction.php with its execute method

public function execute()
    {
        $this->_forward('edit');
    }

And then my Controller Edit.php

public function execute()
    {
        return $this->pageFactory->create();
    }

Then the XML layout handle modulename_promo_coupons_edit.xml to add some blocks to add a form

<body>
        <referenceContainer name="content">
            <block class="Vendor\Coupons\Block\Adminhtml\Promo\Coupons\EditContainer" name="promo_coupons_edit_container" />
            <block class="Vendor\Coupons\Block\Adminhtml\Promo\Coupons\EditContainer\EditForm" name="promo_coupons_edit_form" />
        </referenceContainer>
    </body>

My EditContainer class extends from \Magento\Backend\Block\Widget\Form\Container and my EditForm class from \Magento\Backend\Block\Widget\Form\Generic

What am I doing wrong?

Was it helpful?

Solution

In your \Magento\Backend\Block\Widget\Form\Container class you HAVE to add

protected function _construct(){
        parent::_construct();

        $this->_objectId = 'simple_form';
        $this->_blockGroup = 'Examples_SimpleForm';
        $this->_controller = 'adminhtml_template';

        $this->buttonList->add('save_simple_form', ['label' => __('Save simple form')]);
    }

Take note on $this->_controller = 'adminhtml_template'; which indicates where this Form\Container should seek for Form/Generic classes (this is what i got)

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top