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.

4 Answers 4

2

Override Adminhtml Of
- Block
- Controller

enter image description here

On Image You Can See We Are Overriding the
- Adminhtml of Block File
- Adminhtml of Controller File

etc\adminhtml\di.xml

<?xml version="1.0"?>
<preference
    for="Magento\Customer\Block\Adminhtml\Edit\DeleteButton"
    type="Custom_Vendor\Custom_Module\Block\Adminhtml\Edit\DeleteButton"/>

<preference
    for="Magento\Customer\Controller\Adminhtml\Index\Delete"
    type="Custom_Vendor\Custom_Module\Controller\Adminhtml\Index\Delete"/>

<preference
    for="Magento\Customer\Controller\Adminhtml\Index\MassDelete"
    type="Custom_Vendor\Custom_Module\Controller\Adminhtml\Index\MassDelete"/>

Basically Here I am explaining about the file location where you need to Keep Your File (Any Override Related to Adminhtml ). Here I am Using My File You Can Use As Per Your Requirement

1

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();
}

}
1

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();
}

}
0

Is It important to white controller, if i want to extends only Block/Adminhtml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.