0

How to override module-customer/block/AdminHtml/Group/Edit/Form.php

I have created custom module for that please find my code for that.

etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Customer\Block\Adminhtml\Group\Edit\Form">
    <plugin name="add_form_field" type="ZeroCool\AdvancedReviews\Model\Plugin\Form" sortOrder="1"/>
</type>
<type name="Magento\Customer\Controller\Adminhtml\Group\Save">
    <plugin name="save_field" type="ZeroCool\AdvancedReviews\Model\Plugin\Form" sortOrder="1"/>
</type>
<preference for="Magento\Customer\Model\Group\Edit" type="ZeroCool\AdvancedReviews\Block\Adminhtml\Group\Edit" />  
</config>

Vendor/Package/Block/Adminhtml/Group/Edit.Form.php

<?php 
namespace ZeroCool\AdvancedReviews\Block\Adminhtml\Group\Edit;

use Magento\Customer\Controller\RegistryConstants;

 class Form extends Magento\Customer\Block\Adminhtml\Group\Edit
 {

public function _prepareLayout()
{
    echo "Layout Worked Successfully..."; die();
}

}

There are below exceptions but can't find solutions for them.

2 exception(s): Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid block type: Magento\Customer\Block\Adminhtml\Group Exception #1 (ReflectionException): Class ZeroCool\AdvancedReviews\Block\Adminhtml\Group does not exist

Please guide me.

Thanks in Advance.

0

You have error in your block file

Vendor/Package/Block/Adminhtml/Group/Edit.Form.php

<?php 
namespace ZeroCool\AdvancedReviews\Block\Adminhtml\Group\Edit;

use Magento\Customer\Controller\RegistryConstants;
//Add "/" in start of extends
 class Form extends \Magento\Customer\Block\Adminhtml\Group\Edit
 {

public function _prepareLayout()
{
    echo "Layout Worked Successfully..."; die();
}

}
0

try this code to override block file

etc/di.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Customer\Block\Adminhtml\Group\Edit\Form" type="ZeroCool\AdvancedReviews\Block\Adminhtml\Group\Edit\Form" />
</config>

Vendor/Package/Block/Adminhtml/Group/Edit/Form.php

<?php 
namespace ZeroCool\AdvancedReviews\Block\Adminhtml\Group\Edit;

use Magento\Customer\Controller\RegistryConstants;

 class Form extends \Magento\Customer\Block\Adminhtml\Group\Edit
 {

public function _prepareLayout()
{
    echo "Layout Worked Successfully..."; die();
}

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy